Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3340 Accepted Submission(s): 2534
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<vector> 7 #define mem(x,y) memset(x,y,sizeof(x)) 8 using namespace std; 9 typedef long long LL; 10 const int INF=0x3f3f3f3f; 11 LL e_gcd(LL a,LL b,LL &x,LL &y){ 12 if(!b){ 13 x=1;y=0; 14 return a; 15 } 16 else{ 17 LL d=e_gcd(b,a%b,x,y); 18 LL temp=x; 19 x=y; 20 y=temp-a/b*y; 21 return d; 22 } 23 } 24 LL cal(LL a,LL b,LL c){ 25 LL x,y,gcd; 26 gcd=e_gcd(a,b,x,y); 27 x*=(c/gcd); 28 if(b<0)b=-b; 29 b/=gcd; 30 x=x%b; 31 if(x<=0)x+=b; 32 return x%9973; 33 } 34 int main(){ 35 LL T,n,b; 36 scanf("%lld",&T); 37 while(T--){ 38 scanf("%lld%lld",&n,&b); 39 printf("%lld\n",cal(b,9973,n)); 40 } 41 return 0; 42 }
原文:http://www.cnblogs.com/handsomecui/p/4908602.html