标签:style class blog c code tar
解题思路:求乘法逆元就好了。
1 //Accepted 228 KB 0 ms 2 #include <cstdio> 3 #include <cstring> 4 const int pp = 9973; 5 int extend_euclid(int a,int b,int &x,int &y) 6 { 7 if (b==0) 8 { 9 x=1; 10 y=0; 11 return a; 12 } 13 int d=extend_euclid(b,a%b,x,y); 14 int t=x; 15 x=y; 16 y=t-a/b*y; 17 return d; 18 } 19 int A,B; 20 int a,b,x,y; 21 void slove() 22 { 23 a=B; 24 b=pp; 25 extend_euclid(a,b,x,y); 26 x=(x%b+b)%b; 27 int ans=A*x%pp; 28 printf("%d\n",ans); 29 } 30 int main() 31 { 32 int T; 33 scanf("%d",&T); 34 while (T--) 35 { 36 scanf("%d%d",&A,&B); 37 slove(); 38 } 39 return 0; 40 }
标签:style class blog c code tar
原文地址:http://www.cnblogs.com/djingjing/p/3749421.html