标签:ace 它的 证明 tmp lse ios 乘法 mod 巩固
1 int exgcd(int a, int b, int &x, int &y) 2 { 3 if (b == 0) 4 { 5 x = 1; 6 y = 0; 7 return a; 8 } 9 10 int mod = exgcd(b, a%b, x, y); 11 int tmp = x; 12 x = y; 13 y = tmp - (a / b)*y; 14 return mod; 15 }
1 int Inverse_element(int a, int n) 2 { 3 int gcd, x, y; 4 gcd = exgcd(a, n, x, y); 5 cout << x << endl; 6 if (gcd == 1)return (x%n + n) % n; 7 else return -1; 8 }
1 #include<iostream> 2 #include<malloc.h> 3 #include<string> 4 #include<cmath> 5 #include<conio.h> 6 7 using namespace std; 8 9 int exgcd(int a, int b, int &x, int &y) 10 { 11 if (b == 0) 12 { 13 x = 1; 14 y = 0; 15 return a; 16 } 17 18 int mod = exgcd(b, a%b, x, y); 19 int tmp = x; 20 x = y; 21 y = tmp - (a / b)*y; 22 return mod; 23 } 24 25 int Inverse_element(int a, int n) 26 { 27 int gcd, x, y; 28 gcd = exgcd(a, n, x, y); 29 cout << x << endl; 30 if (gcd == 1)return (x%n + n) % n; 31 else return -1; 32 } 33 34 int main(int argc, const char * argv[]) 35 { 36 int a, n; 37 cin >> a >> n; 38 int mod = Inverse_element(a, n); 39 cout << mod <<endl; 40 _getch(); 41 return 0; 42 }
标签:ace 它的 证明 tmp lse ios 乘法 mod 巩固
原文地址:https://www.cnblogs.com/xiangqi/p/11127060.html