求解二元一次不定方程 mx + ny = gcd(m, n)
1 int ex_gcd(int m, int n, int &x, int &y) 2 { 3 if (n == 0) { 4 x = 1; 5 y = 0; 6 return m; 7 } 8 int tmp, g; 9 g = ex_gcd(n, m % n, x, y); 10 tmp = x; 11 x = y; 12 y = tmp - m / n * y; 13 return g; 14 }
时间: 2024-10-08 10:04:21