RosettaCodeData/Task/Greatest-common-divisor/Java/greatest-common-divisor-5.java

7 lines
150 B
Java
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
public static long gcd(long a, long b){
2013-06-05 21:47:54 +00:00
if(a == 0) return b;
if(b == 0) return a;
if(a > b) return gcd(b, a % b);
return gcd(a, b % a);
2013-04-10 21:29:02 -07:00
}