最小公倍數的性質:公倍數指在兩個或兩個以上的自然數中,如果它們有相同的倍數,這些倍數就是它們的公倍數,其中除0以外最小的一個公倍數,叫做這幾個數的最小公倍數。
最大公因數(公約數)和最小公倍數之間的性質:兩個自然數的乘積等於這兩個自然數的最大公約數和最小公倍數的乘積。我比較常用常用輾轉相除法。
package Days03;
public class Tuse {
public static void main(String[] args) {
GongYueShu(4,6);
GongBeiShu(5,7);
}
public static void GongYueShu(int a,int b){
int c;
while(a%b!=0)
{
c=a%b;
a=b;
b=c;
}
System.out.println(b);
}
public static void GongBeiShu(int a,int b){
int c,d=0;
d=a*b;
while(a%b!=0)
{
c=a%b;
a=b;
b=c;
}
d=d/b;
System.out.println(d);
}
}
結果是:2 35