要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。
Input
数据的第一行是一个T,表示有T组数据。
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
Output
对应每组数据输出(A/B)%9973。
Sample Input
2
1000 53
87 123456789
Sample Output
7922
6060
题意:A/B=k,则k%9973=ans即为答案
A=(kB)%9973=n,(y未知)则有kB=9973y+n
通过欧几里得拓展公式求出kn,再求k即可,
k/nB-y/n9973=gcd(B,9973)=1
#include <iostream>
using namespace std;
const int m=9973;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void gcd( int b,int c ,int &x,int & y)
{
if(c==0) {
x=1,y=0;
return;
}
else{
gcd(c,b%c,x,y);
int temp=x;
x=y;
y=temp-(b/c)*y;
}
}
int main(int argc, char** argv) {
int n,b,x,y,t;
cin>>t;
while(t--){
cin>>n>>b;
gcd(b,m,x,y);
x=(x%m+m)%m;
cout<<((x*n)%m)<<endl;
}
return 0;
}