Problem Description
n×m(1≤n,m≤10000)
Input
T(T≤1000), 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).
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$
其實就是過程等同于求最大公約數。
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int low(int x){ return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int maxn = 1e3 + 10;
int T, n, m, sum;
void gcd(int x, int y)
{
sum += x / y;
if (x%y) gcd(y, x%y);
}
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n, &m);
sum = 0;
gcd(n, m);
printf("%d\n", sum);
}
return 0;
}