1212 最大公约数

1212 最大公约数

 

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 白银 Silver
 
 
 
题目描述 Description

求两个数A和B的最大公约数。 1<=A,B<=2^31-1

输入描述 Input Description

两个整数A和B

输出描述 Output Description

最大公约数gcd(A,B)

样例输入 Sample Input

8 12

样例输出 Sample Output

4

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int a[10001];
 4 int now;
 5 int main()
 6 {
 7     int a,b;
 8     int max=1;
 9     cin>>a>>b;
10     for(int i=2;i<=min(a,b);i++)
11     {
12         if((a%i==0&&b%i==0)&&i>max)
13         max=i;
14     }
15     cout<<max;
16     return 0;
17 }

 

posted @ 2017-03-02 08:19  自为风月马前卒  阅读(212)  评论(0编辑  收藏  举报

Contact with me