public class 最大公约数_辗转相除法 {
/**
* @param args
*/
public static int getGreatestCommonDivisorV2(int a, int b) {
int big = a > b ? a : b;
int small = a < b ? a : b;
if (big % small == 0) {
return small;
}
return getGreatestCommonDivisorV2(big % small, small);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(getGreatestCommonDivisorV2(25, 5));
System.out.println(getGreatestCommonDivisorV2(100, 80));
}
}
最大公约数_辗转相除法
最新推荐文章于 2023-08-09 16:48:26 发布