随笔 - 32  文章 - 2  trackbacks - 0
<2008年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

常用链接

留言簿(3)

随笔档案

文章档案

搜索

  •  

积分与排名

  • 积分 - 8417
  • 排名 - 1249

最新评论

阅读排行榜

评论排行榜

传说中欧几里德发明的求最大公约数的方法
 1 #include <iostream>
 2 using namespace std;
 3 int n;
 4 int list[1001];
 5 
 6 int gcb(int a,int b){
 7     if (a<b){
 8         int m=a;
 9         a=b;
10         b=m;
11         }
12     if (b==0return a;
13     else return gcb(b,a%b);
14     }
15 
16 int main(){
17     scanf("%d",&n);
18     for (int i=1;i<=n;++i) scanf("%d",&list[i]);
19     int ans=list[1];
20     for (int i=2;i<=n;++i) ans=gcb(ans,list[i]);
21     cout<<ans;
22     }
23 


posted on 2008-11-06 20:31 Joseph 阅读(128) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理