Javaは2つの正の整数の最大公約数を求めて、最小の公倍数
5530 ワード
// ,
public class GongYue_Bei {
public static void main(String[] args) {
System.out.println(gcd(100,105));
}
// :
public static int gcd1(int p, int q){
// q 0, p
if(q == 0) {
return p;
}
int r = p % q;
return gcd1(q, r);
}
// p q
public static int gcd(int m,int n){
while (n!=0){
int r = m%n;
m = n;
n = r;
}
return m;
}
// p q
public static int lcm(int p, int q){
int p1 = p;
int q1 = q;
while(q != 0){
int r = p % q;
p = q;
q = r;
}
return (p1*q1)/p;
}
}