Topic link:
http://acm.hdu.edu.cn/showproblem.php?pid=1576
topic:
Problem Description
(A/B)%9973 is required, but since A is very large, we only give n(n=A%9973) (our given A must be divisible by B, and gcd(B,9973) = 1).
Input
The first row of data is a T, indicating that there are T groups of data.
Each set of data has two numbers n (0 <= n < 9973) and B (1 <= B <= 10^9).
Each set of data has two numbers n (0 <= n < 9973) and B (1 <= B <= 10^9).
Output
Corresponding to each group of data output (A/B)% 9973.
Sample Input
2
1000 53
87 123456789
Sample Output
7922
6060
1 /* 2 Problem 3 gives n (0 <= n < 9973) and B (1 <= B <= 10^9), calculate (A/B)%9973 4 where n=A%9973, A must be able to Divisible by B, and gcd(B, 9973) = 1 5 6 Problem- solving ideas 7 Set X=(A/B)%9973, then A/B=K*9973+X (K is a positive integer) 8 is A= K*9973*B+X*B 9 10 and n=A%9973, then A=p*9973+n 11 12 Combining the two formulas can get p*9973+n=K*9973*B+X*B 13 shift The item can be obtained as p*9973-K*9973*B=X*Bn 14 , that is, 9973*(pK*B)=X*Bn 15 Obviously, the remainder of 9973 on the left is equal to 0, then 0=(X*Bn)%9973 16 At this time, you can directly enumerate the value of X. In addition, it is noted that X*B may exceed the range of int, and the congruence operation needs to be used. Of course, it can also be directly converted to long long type. 17 (ab)%n=((a%n)-(b%n)+n)%n 18 (a*b)%n=(a%n)*(b%n)%n 19 故(x*B-n)%9973=( ((X%9973)*(B%9973)%9973) -(n%9973)+9973 )%9973 20 */ 21 22 #include<cstdio> 23 24 int main() 25 { 26 int t,n,X; 27 long long B; 28 scanf("%d",&t); 29 while(t--){ 30 scanf("%d%lld",&n,&B); 31 for(X=0;;X++){ 32 if((((X%9973)*(B%9973)%9973) - (n%9973)+9973)%9973 == 0){ 33 printf("%d\n",X); 34 break; 35 } 36 } 37 } 38 return 0; 39 } 40