Pro.ID22190 TitleReprogramming Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22190 AC0 Submit0 Ratio- 时间&空间限制描述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. 输入There're multiple cases. For each case there's one line containing two integers for x and y. Input is end with two 0's. 输出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 0's. Output For each case output the result in a single line. Sample Input 2 2
1 1
0 0 Sample Output 2
1 Source 样例输入2 2
1 1
0 0 样例输出2
1 作者 |