Problem Description
要求(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)。
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
Output
对应每组数据输出(A/B)%9973。
Sample Input
2 1000 53 87 123456789
Sample Output
7922 6060
思路:扩展欧几里得算法的应用
AC代码:
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#define N 9973
using namespace std;
void _gcd(int a,int b,int &x1,int &y1)
{
if(!b) x1=1,y1=0;
else
{
_gcd(b,a%b,x1,y1);
int temp=x1;
x1=y1;
y1=temp-a/b*x1;
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int a,c;
scanf("%d%d",&c,&a);
int b=9973;
int x1,y1;
_gcd(a,b,x1,y1);
printf("%d\n",((x1%N)*(c%N)%N+N)%N);
}return 0;
}