1723. Reprogramming

1723. Reprogramming

Total:

1127

Accepted:

470

Rating:

1.6/5.0(8 votes)

 

 

 

Time Limit: 1sec    Memory Limit:32MB

Description

Recently Doctor Guan has discovered two new kinds of bacteria and named them BT-U and BT-V .BT-U and BT-V are quite special, they can only live with the help of each other. Doctor Guan did several experiments on BT-U and BT-V, here’re the results:
Put 100 BT-Us and 80 BT-Vs together , one minute later , there are 20 BT-Us and 80 BT-Vs ,one minute later again , there are 20 BT-Us and 60 BT-Vs, then 20 BT-Us and 40 BT-Vs , then 20 BT-Us and 20 BT-Vs , then these 20 BT-Us and 20 BT-Vs keep alive.
Put 3 BT-Us and 5 BT-Vs together , one minute later , there are 3 BT-Us and 2 BT-Vs , one more minute later there are 1 BT-U and 2 BT-Vs, then 1 BT-U and 1 BT-V, and this 1 BT-U and 1 BT-V keep alive.
According to the results above, Doctor Guan has reached a conclusion that when putting x BT-Us and y BT-Vs together, if x=y then they keep alive, if x<y then x BT-Vs would die in one minute, if x>y then y BT-Us would die in one minute.
Doctor Guan has made a program to determine how many BT-Us and BT-Vs survive when putting x BT-Us and y BT-Vs together. Program is as follow :
#include<fstream.h>
ifstream filein(“reprog.in”);
ofstream fileout(“reprog.out”);
int main(){
  long x,y;
  for(;;){
filein>>x>>y;
if(x<=0 || y<=0)break;
while(x!=y)if(x>y)x-=y;else y-=x;
fileout<<x<<endl;
}
  return 0;
}
But this program is quite inefficient; Doctor Guan needs your help to improve it.

Input

There’re multiple cases. For each case there’s one line containing two integers for x and y. Input is end with two 0s.

Output

For each case output the result in a single line.

Sample Input

Copy sample input to clipboard

2 2

1 1

0 0

Sample Output

2

1

// Problem#: 1723

// Submission#: 1986097

// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/

// All Copyright reserved by Informatic Lab of Sun Yat-sen University

#include<iostream>

#include<stdio.h>

int gcd(int a ,int b){

    int temp;

    while(b!=0){

                temp = a%b;

                a = b;

                b = temp;

    }

    return a;

}

using namespace std;

int main(){

    int n;

    int a,b;

    cin>>a>>b;

    while(a>0 && b>0){

        cout<<gcd(a,b)<<endl;

        cin>>a>>b;

    }

    return 0;

}    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值