题目
原题链接:B. Weird Subtraction Process
题意
按照以下步骤进行操作:
1:If a = 0 or b = 0, end the process. Otherwise, go to step 2;
2:If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3;
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>
using namespace std;
int main() {
long long a,b;
cin>>a>>b;
while(a!=0 && b!=0){
if(a>=2*b) a%=2*b;
else{
if(b>=2*a) b%=2*a;
else break;
}
}
printf("%lld %lld\n",a,b);
return 0;
}
网友评论