题目链接 codeforces 946 B
题意:
- If a = 0 or b = 0, end the process. Otherwise, go to step 2;
- If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3;
- If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.
题解:
运用欧几里得的取余法求公倍数的思想,不然,大数相减会超时
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
ll a, b;
cin >> a >> b;
while(1){
if(a == 0 || b == 0){
break;
}
else if(a >= b * 2){
a = a % (b * 2);
}
else if(b >= a * 2){
b = b % (a * 2);
}
else{
break;
}
}
cout << a << " " << b << endl;
return 0;
}