标签:pow 费马小定理 int 求逆 while def text type 质数
//法1:费马小定理求逆元,p需为质数 :
typedef long long ll;
const int MOD = 9973;
ll PowerMod(ll a, ll b, ll p) { //(a^b)%p
ll ans = 1;
a = a%p;
while (b>0) {
if (b & 1) ans = (ans*a) % p;
b >>= 1;
a = (a*a) % p;
}
return ans;
}
int main()
{
ll n, b;
scanf("%d%d", &n, &b); //求(n/b)%MOD
printf("%lld\n", (n*PowerMod(b, MOD - 2, MOD)) % MOD);
return 0;
}
标签:pow 费马小定理 int 求逆 while def text type 质数
原文地址:https://www.cnblogs.com/zhbf/p/9889004.html