推演图示
public class A031_扩展欧几里得_贝祖公式_一步之遥 {
static int x, y;
public static void main(String[] args) {
int ans = work(97, -127, 1);
if (ans != 999)
System.out.println(x + " " + y);
else
System.out.println("无解");
System.out.println(x + y);
}
public static int work(int a, int b, int m) {
int d = gcd(a, b);
if (m % d != 0)
return 999;
int t = m / d;
x *= t;
y *= t;
return d;
}
public static int gcd(int a, int b) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = gcd(b, a % b);
int x1 = x;
x = y;
y = x1 - a / b * y;
return d;
}
}