Greatest common divisor and least common multiple - find the least common multiple

Reference: https: //www.cnblogs.com/schips/p/10658253.html

The method of seeking the least common multiple of:

Method 1: Method prime factor decomposition

Method 2: Method formula

The method of seeking the greatest common divisor:

Method 1: Euclidean algorithm (Euclid method)

Method 2: exhaustive method (enumeration method)

Method 3: Method Decreases

Method 4: Stein algorithm

 

Method using the formula + Euclidean find the least common multiple of the two numbers

//
#include<stdio.h>
int maxComDiv(int a,int b){
	if(a%b == 0)
		return b;
	else
		return maxComDiv(b,a%b); 
} 
int main(){
	int a,b,c;
	scanf("%d%d",&a,&b);
	if(a>b)
		c = maxComDiv(a,b);	//求a,b的最大公约数
	else
		c = maxComDiv(b,a); 
	printf("%d",(a*b)/c);
	return 0; 
} 

  

Guess you like

Origin www.cnblogs.com/Hqx-curiosity/p/12210935.html