博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NEFU 84
阅读量:4649 次
发布时间:2019-06-09

本文共 696 字,大约阅读时间需要 2 分钟。

其实同POJ 1061

#include 
#include
#include
#include
using namespace std;long long gcd(long long a,long long b){ if(b==0) return a; return gcd(b,a%b);}void exgcd(long long a,long long b,long long &x,long long &y){ if(b==0){ x=1; y=0; return; } exgcd(b,a%b,x,y); long long t=x; x=y; y=t-a/b*y;}int main(){ int t; long long n,d,x,y,a,b,c; scanf("%d",&t); while(t--){ cin>>n>>d>>x>>y; a=n; b=d; c=y-x; long long r=gcd(a,b); if(c%r!=0){ printf("Impossible\n"); continue; } a/=r; b/=r; c/=r; exgcd(a,b,x,y); y*=c; printf("%lld\n",(y%a+a)%a); } return 0;}

  

转载于:https://www.cnblogs.com/jie-dcai/p/3939549.html

你可能感兴趣的文章