标签:des style blog http io ar color os sp
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algorithm> 7 #define LL __int64 8 const int maxn = 1e3 + 10; 9 const int mo = 9973; 10 using namespace std; 11 12 void exgcd(LL a, LL b, LL &d, LL &x, LL &y) 13 { 14 if(!b) {d = a; x = 1; y = 0;} 15 else{ exgcd(b, a%b, d, y, x); y -= x*(a/b); } 16 } 17 18 LL mo_reve(LL a, LL n) 19 { 20 LL x, y; 21 LL d; 22 exgcd(a, n, d, x, y); 23 if(d==1) return (x%n+n)%n; 24 else return -1; 25 } 26 27 int main() 28 { 29 int t, n, b; 30 scanf("%d", &t); 31 while(t--) 32 { 33 scanf("%d%d", &n, &b); 34 int x = mo_reve(b, mo); 35 printf("%d\n", n*x%mo); 36 } 37 return 0; 38 }
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/bfshm/p/4106844.html