题目链接
题解:
因为A%9973/B%9973 != A/B%9973,所以要用到逆元,求出B关于9973的逆元,在乘n就行了(A/B=A乘B的逆元),我这里用的快速幂求逆元。
不懂逆元的可以点这里
代码:
#include<iostream>
#include<stdio.h>
using namespace std;
const int MOD=9973;
typedef long long LL;
LL n,b;
LL mod_pow(LL x,int m)
{
LL ans=1;
while(m){
if(m&1) ans=ans*x%MOD;
x=x*x%MOD;
m>>=1;
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%I64d%I64d",&n,&b);
LL inv,sum;
inv=mod_pow(b,MOD-2);
sum=inv*n%MOD;
printf("%I64d\n",sum);
}
return 0;
}