首页 > 代码库 > 分火腿(C++)

分火腿(C++)

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#define mod 1000000007
#define ll long long
using namespace std;
int T;
int n,m;
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
T=read();
while(T--)
{
n=read();m=read();
printf("%d\n",m-gcd(n,m));
}
return 0;
}

分火腿(C++)