gcd(a,b)=gcd(b,a) java
gcd(a,b)=gcd(b, a mod b) spa
遞歸方式: code
public static int gcd(int a, int b){ if(a % b == 0){ return b; }else{ return gcd(b, a % b); } } 非遞歸方式:public static void gcb(int a, int b){ int temp; if(a<b){ //將大數放在a上 temp = b; b = a; a = temp; } while(b != 0){ temp = a % b; a = b; b = temp; }