A/B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12428 Accepted Submission(s): 9983
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
Author
xhd
Source
Recommend
解题思路: 把B的逆元求解出来 就行了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 typedef long long ll; 7 ll t; 8 ll d1,d2,d3,d4; 9 ll X,Y,a,b,c; 10 ll GDC; 11 12 ll gdc(ll x,ll y){ 13 return y==0?x:gdc(y,x%y); 14 } 15 16 void extend_gdc(ll a,ll b,ll &X,ll &Y){ 17 if(b==0){ 18 X=1; 19 Y=0; 20 return; 21 } 22 extend_gdc(b,a%b,X,Y); 23 ll temp=X; 24 X=Y; 25 Y=temp-a/b*Y; 26 } 27 28 int main(){ 29 ios::sync_with_stdio(false); 30 cin>>t; 31 while(t--){ 32 cin>>d1>>d2; 33 a=d2,b=9973; 34 GDC=gdc(a,b); 35 extend_gdc(a,b,X,Y); 36 ll p=b/GDC; 37 if(p<0) p=-p; 38 X%=p; 39 if(X<0) X+=p; 40 ll A=9973+d1; 41 cout << A*X%9973 << endl; 42 } 43 return 0; 44 }