首页 > 其他 > 详细

BestCoder Round #75 - King's Phone

时间:2016-03-13 00:26:11      阅读:312      评论:0      收藏:0      [点我收藏+]
Problem Description
It is the king‘s birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1n,m10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut the rectangle cake into two pieces, one of which should be a square cake.. Since he loves squares , he will cut the biggest square cake. He will continue to do that until all the pieces are square. Now can you tell him how many pieces he can get when he finishes.
 

 

Input
The first line contains a number T(T1000), the number of the testcases.

For each testcase, the first line and the only line contains two positive numbers n,m(1n,m10000).
 

 

Output
For each testcase, print a single number as the answer.
 

 

Sample Input
2 2 3 2 5
 

 

Sample Output
3 4 hint: For the first testcase you can divide the into one cake of $2\times2$ , 2 cakes of $1\times 1$
 

 

Source
 

 

切正方形蛋糕,两条边轮流互减

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 #define LL long long
 5 int m,n,t;
 6 LL ans;
 7 int main(){
 8     scanf("%d",&t);
 9     while(t--){
10         scanf("%d%d",&m,&n);
11         ans=0;
12         while(m>0&&n>0){
13             if(m>n) swap(m,n);
14             n-=m;
15             ans++;
16         }
17         cout<<ans<<endl;
18     }
19 } 

 

BestCoder Round #75 - King's Phone

原文:http://www.cnblogs.com/nicetomeetu/p/5270332.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!