public class Euclideanalgorithm { public static int getGCD(int a, int b) { if(a < 0 || b < 0) return -1; if(a < b) { int c = b; b = a; a = c; } int c = a % b; if(c == 0) return b; else return getGCD(b, c); } public static void main(String[] args) { System.out.println(getGCD(1254, 390)); } }
世界上最早的算法:辗转相除法(求两个自然数最大公约数)
猜你喜欢
转载自startfromzero.iteye.com/blog/1886254
今日推荐
周排行