You’ve got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You’ve got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
input
2
4 17
7 987654321
output
8
141093479
My Answer Code:
/*
Author:Albert Tesla Wizard
Time:2021/3/12 18:00
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
int a,b,ans=0;
cin>>a>>b;
int Min=min(a,b);
int Max=max(a,b);
while(Max%Min!=0)
{
ans+=Max/Min;
int temp=Min;
Min=Max%Min;
Max=temp;
}
ans+=Max/Min;
cout<<ans<<'\n';
}
return 0;
}