noip赛前模拟

比赛就是艺术,艺术就是爆炸。

T1

输出m-gcd(n,m)

#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
LL n,m,t;
template <class T> void read(T&x)
{
  x=0;char c=getchar();int f=0;
  while(c<'0'||c>'9'){f|=(c=='-');c=getchar();}
  while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^=48),c=getchar();
  x=f?-x:x;
}
LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);}
int main()
{
  freopen("hdogs.in","r",stdin);
  freopen("hdogs.out","w",stdout);
  read(t);
  while(t--)
  {
      read(n);read(m);
      printf("%d\n",max(m-gcd(n,m),0));
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
View Code

 

posted @ 2017-10-24 13:22  新手-周  阅读(103)  评论(0编辑  收藏  举报