android GCD activity

今天要來寫GCD程式,因為很多面試時都在考這題,沒背公式的大都不會寫...
ps:沒背公式的話,花5分鐘推理是可以想出來,但其他題都別做了...

配合遞迴(Recursion)....
公式是:
public int gcd(int m, int n){
     return (n>0)?gcd(n,m%n):m;
 }


留言