**链接:****传送门 **
思路:
- 现在给出 n = A % 9973,n = A - A/9973×9973,已知 B|A ,设 A = Bx,可以得到如下形式的式子:Bx + 9973×y = n ,因为gcd( B , 9973 ) = 1,所以可以用 exgcd 来求出 Bx + 9973×y = 1 的 x 值,A/B = x * n ,所以最后的答案就是 ( x * n%MOD + MOD ) %MOD
/*************************************************************************
> File Name: hdu1576.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月10日 星期三 22时54分37秒
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
const int MOD = 9973;
int exgcd(int a,int b,int &x,int &y){
if(b==0){
x = 1; y = 0; return a;
}
int d = exgcd(b,a%b,x,y);
int tmp = x;
x = y; y = tmp - a/b*y;
return d;
}
int main(){
int t,n,B;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&B);
int x , y;
int d = exgcd(B,MOD,x,y);
x *= n;
printf("%d
", (x%MOD + MOD)%MOD );
}
return 0;
}