King's Cake
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 827 Accepted Submission(s): 596
For each testcase, the first line and the only line contains two positive numbers n,m(1≤n,m≤10000).
/*
貪心:對於長n,寬m,排序
1: n,m +1;
2: max(m,n-m),min(m,n-m) +1;
3: ....
直到n==n-m;
最後再加一個剩下的
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int n,m;
int main(){
int t,re;
cin>>t;
while(t--){
re=1;
cin>>n>>m;
if(n==m){
cout<<re<<endl;
continue;
}
else if(n<m){
int tmp=n;
n=m;
m=tmp;
}
while(n!=m){
re++;
n=n-m;
if(n<m){
int tmp=n;
n=m;
m=tmp;
}
}
cout<<re<<endl;
}
return 0;
}