public static int gcd(int x,int y){
if(x==0){
return y;
}
if(y==0){
return x;
}
if(x<y){
return gcd(y%x,x);
}
return gcd(y,x%y);
}
如此简单的算法 为什么我们上学学习最大公约数的时候没有学到过呢 天天的被公式被课文 我们牛逼的教育
public static int gcd(int x,int y){
if(x==0){
return y;
}
if(y==0){
return x;
}
if(x<y){
return gcd(y%x,x);
}
return gcd(y,x%y);
}