gcd方法:欧几里得算法
/** * 第二章练习 2.16 * @param max * @param min * @return */
public static long gcdd(long a, long b){
long max=a>b?a:b;
long min=a>b?b:a;
if(max == 0|| min == 0) {//base case
return max==0?min : max;
}else if(max%2==0&&min%2==0) {
return 2*gcdd(max/2,min/2);
}else if(max%2==0&&min%2==1) {
return gcdd(max/2,min);
}else if(max%2==1&&min%2==0) {
return gcdd(max,min/2);
}else {
return gcdd((max+min)/2,(max-min)/2);
}
}