AcWing 877. 扩展欧几里得算法(java没有变量引用)
原题链接
简单
作者:
宇小苏
,
2020-02-23 13:25:29
,
所有人可见
,
阅读 1296
Java代码
import java.util.*;
class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-- >0){
int a = sc.nextInt();
int b = sc.nextInt();
int d = exgcd(a, b);
System.out.println(x + " " + y);
}
}
private static int x, y;
private static int exgcd(int a, int b){
if(b == 0){
x = 1;
y = 0;
return a;
}
int d = exgcd(b, a % b);
int tmp = x;
x = y;
y = tmp - a / b * y;
return d;
}
}
刚想着没有引用传值怎么搞,就来看看题解的绝活了!