BestCoder Round #75 - King's Phone
Posted nicetomeetu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BestCoder Round #75 - King's Phone相关的知识,希望对你有一定的参考价值。
Problem Description
It is the king‘s birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . 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, the number of the testcases.
For each testcase, the first line and the only line contains two positive numbers n,m(1≤n,m≤10000).
For each testcase, the first line and the only line contains two positive numbers n,m(1≤n,m≤10000).
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的主要内容,如果未能解决你的问题,请参考以下文章
BestCoder Round #75 King's Order dp:数位dp