You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
// https://vjudge.csgrandeur.cn/problem/HDU-1576
|
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
typedef long long LL;
|
|
|
|
|
/*
|
|
|
|
|
测试用例
|
|
|
|
|
2
|
|
|
|
|
1000 53
|
|
|
|
|
87 123456789
|
|
|
|
|
|
|
|
|
|
答案
|
|
|
|
|
7922
|
|
|
|
|
6060
|
|
|
|
|
|
|
|
|
|
总结:
|
|
|
|
|
1、如果使用费马小定理+快速幂求逆元,一定要注意使用LL,防止爆int。
|
|
|
|
|
*/
|
|
|
|
|
const int MOD = 9973;
|
|
|
|
|
|
|
|
|
|
LL qmi(LL a, LL k, LL p) {
|
|
|
|
|
LL res = 1;
|
|
|
|
|
while (k) {
|
|
|
|
|
if (k & 1) res = res * a % p; //如果res是int,可能会越界
|
|
|
|
|
k >>= 1;
|
|
|
|
|
a = a * a % p; //如果a是int, 可能会越界
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int T;
|
|
|
|
|
cin >> T;
|
|
|
|
|
while (T--) {
|
|
|
|
|
LL a, b;
|
|
|
|
|
cin >> a >> b;
|
|
|
|
|
LL x;
|
|
|
|
|
x = qmi(b, MOD - 2, MOD); // b理解为分母,同余MOD的逆元,变除法为乘法
|
|
|
|
|
LL res = a * x % MOD; // a* b在模MOD下的逆元 x
|
|
|
|
|
printf("%lld\n", res);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|