greatest common divisor gcd; least common multiple

greatest common divisor

Euclidean algorithm (rolling and dividing method) :

  • Greatest Common Divisor (Greatest Common Divisor) abbreviated as GCD
  • g c d ( a ,   b ) = g c d ( b ,   a   m o d   b ) gcd(a,\ b) = gcd(b,\ a\ mod\ b) gcd(a, b)=gcd(b, a mod b)
private static int gcd(int a, int b) {
    
    
	return (b == 0 ? a : gcd(b, a % b));
}

gcd ( a , b ) = gcd ( a , b − a ) . where a ≤ b gcd(a,\ b)=gcd(a,\ ba).\ where a\ ≤\ bgcd(a, b)=gcd(a, ba ) . _ _   b

least common multiple

Least common multiple :

  • Least common multiple of two numbers * Greatest common divisor = product

Je suppose que tu aimes

Origine blog.csdn.net/m0_60641871/article/details/130008764
conseillé
Classement