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.

42 lines
895 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 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;
}