美文网首页
CodeFoeces-946B

CodeFoeces-946B

作者: ss5smi | 来源:发表于2018-03-11 13:57 被阅读0次

题目

原题链接: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;
}

相关文章

  • CodeFoeces-946B

    题目 原题链接:B. Weird Subtraction Process 题意 按照以下步骤进行操作:1:If a...

网友评论

      本文标题:CodeFoeces-946B

      本文链接:https://www.haomeiwen.com/subject/gabvfftx.html