用辗转相除法求3869和6497的最小公倍数.

来源:百度知道 编辑:UC知道 时间:2024/05/17 01:41:44

被除数 / 除数 = 商 ...... 余数
6497 / 3869 = 1 ...... 2628
3869 / 2628 = 1 ...... 1241
2628 / 1241 = 2 ...... 146
1241 / 146 = 8 ...... 73
146 / 73 = 2 ...... 0
因此最大公约数为:73
最小公倍数=两数之积/最大公约数=6497*3869/73=25136893

package commonDivisor;
/**
* @author wanggang
*
*/
public class CommonDivisor {
public static int commonDivisor(int a,int b){

int m = max(a,b);
int n = min(a,b);
int r=0;
while(m%n != 0){
r = m%n;
m = n;
n = r;
}
return n;
}

private static int min(int m, int n) {
if(m>n)
return n;
else
return m;
}

private static int max(int m, int n) {
if(m>n)
return m;
else
return n;
}

public static void main(String[] args){
System.out.println(commonDivisor(8,26));
}
}

/**
*
*/