HDU A/B

要求(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

已知

n=A%9973

A%B=0

B与9973互素(GCD(B,9973)=1)

x=(A/B)%9973(x是最终想计算的值,满足0<=x<=9972)

9973k+x=A/B(k为整数)

A=9973Bk+xB

因为  n=A%9973

       A=9973Bk+xB

所以   xB%9973=n

得      xB=n+9973y

故:(xB-n)%9973=0

#include<iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	int a,b;
	int i;
    while(t--){
	    cin>>a>>b;
		for( i=0;i<9973;i++)
		    if((((b%9973)*i)%9973-a)%9973==0)          
			    break;             
		printf("%d\n",i); 
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/red_red_red/article/details/84429952