与提交的代码相比,我的代码未按预期运行。为什么它们工作方式不同?
提交的代码:
final
我的代码:
static int x, y;
static int extendedEuclid(int a, int b) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = extendedEuclid(b, a % b);
int x1 = y;
int y1 = x - a / b * y;
x = x1;
y = y1;
return d;
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
while (sc.hasNextInt()) {
int a = sc.nextInt(), b = sc.nextInt();
int d = extendedEuclid(a, b);
out.printf("%d %d %d\n", x, y, d);
out.flush();
}
}