Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
6029 | 邓小龙 | 15求两个数的最大公约数 | C++ | Accepted | 0 MS | 264 KB | 479 | 2024-12-28 10:01:10 |
/*思路: 1.a,b,c,其中c=a%b 2.如果c==0,那么结束循环,b就是要找的最大公约数 否则:a=b,b=c,继续循环 */ #include<iostream> #include<cmath> using namespace std; int main(){ int a,b,i,cnt=0; cin>>a>>b; i=a%b; while(i!=0){//辗转相除法或者欧几里得算法//gcd:greatest common divsior a=b; b=i; i=a%b; //cnt++; } cout<<b<<endl; //cout<<cnt<<endl; return 0; }