题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576
2 1000 53 87 123456789
7922 6060
PS:
n = A%9973, 设A / 9973 = y;
A / B = x --->>>> A = B * x;
那么就有: B*x - 9973 * y = n;
代码如下:
#include <cstdio> #include <cstring> #include <cmath> typedef __int64 LL; LL exgcd(LL a,LL b,LL &x,LL &y) { if(b == 0) { x = 1; y = 0; return a; } LL r = exgcd(b,a%b,x,y); LL t = x; x = y; y = t-a/b*y; return r; } LL cal(LL a, LL b, LL c) { LL x, y; LL tt = exgcd(a, b, x, y); if(c%tt) return -1; x *= c/tt; b/=tt; if(b < 0) b = -b; LL ans = x%b; if(ans < 0) ans += b; return ans; } int main() { LL n, b; LL t; scanf("%I64d",&t); while(t--) { scanf("%I64d%I64d",&n,&b); LL ans = cal(b,9973,n); if(ans == -1) printf("Impossible\n"); else printf("%I64d\n",ans); } return 0; }
原文地址:http://blog.csdn.net/u012860063/article/details/39801219