定理:兩個整數的最大公約數等于其中較小的那個數和兩數相除余數的最大公約數,gcd(a,b) = gcd(b,a%b) (a>b)
public static int GCD(int a,int b) { if(b==0) return a; return GCD(b,a%b); }
求最小公倍數
最小公倍數 = 兩數乘積/最大公約數
public int commonMultiple(int a,int b){ return a * b / GCD(a,b) }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/161502.html
標籤:Java
上一篇:非常詳盡的 Shiro 架構決議
