1212 最大公约数

时间:2022-05-07
本文章向大家介绍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 }