It's Tejasi's birthday and her mom has prepared hot dogs. There are N hot dogs and M people and her mom wants to divide the hotdogs equally. Tejasi wants to calulate the minimum number of cuts required to distribute the hot dogs equally.
Help Tejasi in finding out the number of cuts required.
In order to divide the hot dogs, the number of cuts splitting individual hot dogs must be as small as possible.
Help her calculate the minimum total number of cuts needed to carry out the desired division.
The first line contains T the no of test cases.
The next t lines contain two positive integers, N and M , the number of hot dogs and eaters, respectively.
The output consists of t lines which contains required minimum number of cuts.
Input: 3 2 6 3 4 6 2 Output: 4 3 0
gcd裸题。
#include
#include
#include
#include
#include
#include
using namespace std;
int T,n,m,s;
int gcd(int x,int y)
{
if(y==0) return x;
return gcd(y,x%y);
}
int main()
{
scanf("%d",&T);
while(T--)
{scanf("%d%d",&n,&m);
s=gcd(n,m);
printf("%d\n",m-s);
}
return 0;
}