public static int gcd(int a, int b) {
int n1 = Math.abs(a);
int n2 = Math.abs(b);
int remainder = n1 % n2;
while (remainder > 0) {
n1 = n2;
n2 = remainder;
remainder = n1 % n2;
}
return n2;
}
时间: 2024-10-22 03:56:08
public static int gcd(int a, int b) {
int n1 = Math.abs(a);
int n2 = Math.abs(b);
int remainder = n1 % n2;
while (remainder > 0) {
n1 = n2;
n2 = remainder;
remainder = n1 % n2;
}
return n2;
}