Chương trình LCM trong Python

LCM [Bội chung nhỏ nhất] của hai số là số nhỏ nhất chia hết cho cả hai số.  

Ví dụ: LCM của 15 và 20 là 60 và LCM của 5 và 7 là 35

Một giải pháp đơn giản là tìm tất cả các thừa số nguyên tố của cả hai số, sau đó tìm hợp của tất cả các thừa số có trong cả hai số. Cuối cùng, trả về sản phẩm của các yếu tố trong hiệp hội

Một giải pháp hiệu quả dựa trên công thức dưới đây cho LCM của hai số 'a' và 'b'.  

   a x b = LCM[a, b] * GCD [a, b]

   LCM[a, b] = [a x b] / GCD[a, b]

Chúng ta đã thảo luận về hàm tìm ƯCLN của hai số. Sử dụng GCD, chúng ta có thể tìm thấy LCM.  

Dưới đây là triển khai ý tưởng trên

C++




// C++ program to find LCM of two numbers

#include

using namespace std;

 

// Recursive function to return gcd of a and b

long long

LCM of 15 and 20 is 60
0long long
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
4long long
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
8

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers0// C++ program to find LCM of two numbers1 // C++ program to find LCM of two numbers2

// C++ program to find LCM of two numbers3______138_______4 // C++ program to find LCM of two numbers5

// C++ program to find LCM of two numbers0// C++ program to find LCM of two numbers4 // C++ program to find LCM of two numbers8

// C++ program to find LCM of two numbers9

 

#include 0

long long #include 3

LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
4
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
8

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers3_______138_______4 using1

// C++ program to find LCM of two numbers9

using3

using4

LCM of 15 and 20 is 60
3 using6

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers3______1_______3 namespace0

// C++ program to find LCM of two numbers3_______141_______2namespace3 namespace4namespace5

namespace6_______141_______7namespace8 namespace9

// C++ program to find LCM of two numbers3_______138_______4 std;2

// C++ program to find LCM of two numbers9

C




std;4

std;5

 

// Recursive function to return gcd of a and b

LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
0
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
4
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
8

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers3_______138_______1 // Recursive function to return gcd of a and b6

// Recursive function to return gcd of a and b7// C++ program to find LCM of two numbers4 // Recursive function to return gcd of a and b9

// C++ program to find LCM of two numbers3_______138_______4 long2

// C++ program to find LCM of two numbers9

 

#include 0

LCM of 15 and 20 is 60
3 #include 3
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
4
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
8

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers3_______138_______4 using1

// C++ program to find LCM of two numbers9

 

using4

LCM of 15 and 20 is 60
3 using6

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers3______1_______3 namespace0

// C++ program to find LCM of two numbers3_______1_______04

LCM of 15 and 20 is 60
05
LCM of 15 and 20 is 60
06
LCM of 15 and 20 is 60
07

// C++ program to find LCM of two numbers3_______138_______4 std;2

// C++ program to find LCM of two numbers9

Java




LCM of 15 and 20 is 60
12

LCM of 15 and 20 is 60
13
LCM of 15 and 20 is 60
14

LCM of 15 and 20 is 60
15
LCM of 15 and 20 is 60
16
LCM of 15 and 20 is 60
17

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers3______1_______20

// C++ program to find LCM of two numbers3_______1_______22

LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
0_______1_______3
LCM of 15 and 20 is 60
4
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
8

// C++ program to find LCM of two numbers3______1_______9

// Recursive function to return gcd of a and b7// C++ program to find LCM of two numbers1

LCM of 15 and 20 is 60
33
LCM of 15 and 20 is 60
34
LCM of 15 and 20 is 60
35

LCM of 15 and 20 is 60
36_______138_______4 // Recursive function to return gcd of a and b9

// Recursive function to return gcd of a and b7// C++ program to find LCM of two numbers4 long2

// C++ program to find LCM of two numbers3____138_______9

// C++ program to find LCM of two numbers3

// C++ program to find LCM of two numbers3______1_______46

// C++ program to find LCM of two numbers3_______1_______22

LCM of 15 and 20 is 60
3 #include 3
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
4
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
8

// C++ program to find LCM of two numbers3______1_______9

// Recursive function to return gcd of a and b7// C++ program to find LCM of two numbers4 using1

// C++ program to find LCM of two numbers3____138_______9

// C++ program to find LCM of two numbers3

// C++ program to find LCM of two numbers3______1_______64

// C++ program to find LCM of two numbers3_______1_______15

LCM of 15 and 20 is 60
22
LCM of 15 and 20 is 60
68
LCM of 15 and 20 is 60
69

// C++ program to find LCM of two numbers3______1_______9

// Recursive function to return gcd of a and b7

LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
74
LCM of 15 and 20 is 60
75_______1_______76
LCM of 15 and 20 is 60
77
LCM of 15 and 20 is 60
78

// Recursive function to return gcd of a and b7

LCM of 15 and 20 is 60
80namespace3
LCM of 15 and 20 is 60
82

LCM of 15 and 20 is 60
83namespace5
LCM of 15 and 20 is 60
85

LCM of 15 and 20 is 60
86namespace8
LCM of 15 and 20 is 60
88

// C++ program to find LCM of two numbers3____138_______9

// C++ program to find LCM of two numbers9

Python3




LCM of 15 and 20 is 60
92

 

LCM of 15 and 20 is 60
93

LCM of 15 and 20 is 60
94
LCM of 15 and 20 is 60
95

// C++ program to find LCM of two numbers3_______138_______1

LCM of 15 and 20 is 60
98
LCM of 15 and 20 is 60
99
LCM of 15 and 20 is 60
99
LCM of 15 and 20 is 60
34// C++ program to find LCM of two numbers02

// Recursive function to return gcd of a and b7// C++ program to find LCM of two numbers4 // C++ program to find LCM of two numbers05

// C++ program to find LCM of two numbers3_______138_______4 // C++ program to find LCM of two numbers08// C++ program to find LCM of two numbers09 // C++ program to find LCM of two numbers10

 

// C++ program to find LCM of two numbers11

LCM of 15 and 20 is 60
94 // C++ program to find LCM of two numbers13

// C++ program to find LCM of two numbers3_______138_______4 // C++ program to find LCM of two numbers16// C++ program to find LCM of two numbers17// C++ program to find LCM of two numbers17 // C++ program to find LCM of two numbers19// C++ program to find LCM of two numbers20 // C++ program to find LCM of two numbers05

 

// C++ program to find LCM of two numbers22

LCM of 15 and 20 is 60
98
LCM of 15 and 20 is 60
99
LCM of 15 and 20 is 60
75

// C++ program to find LCM of two numbers05

LCM of 15 and 20 is 60
99
LCM of 15 and 20 is 60
77

// C++ program to find LCM of two numbers29_______1_______05// C++ program to find LCM of two numbers31// C++ program to find LCM of two numbers32// C++ program to find LCM of two numbers33// C++ program to find LCM of two numbers34// C++ program to find LCM of two numbers35// C++ program to find LCM of two numbers36

 

// C++ program to find LCM of two numbers37

C#




// C++ program to find LCM of two numbers38

// C++ program to find LCM of two numbers39

using // C++ program to find LCM of two numbers41

LCM of 15 and 20 is 60
16 // C++ program to find LCM of two numbers43

// C++ program to find LCM of two numbers3

// C++ program to find LCM of two numbers3______138_______46

// C++ program to find LCM of two numbers3____138_______48

// C++ program to find LCM of two numbers3_______1_______22

LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
0_______1_______3
LCM of 15 and 20 is 60
4
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
8

// C++ program to find LCM of two numbers3______1_______9

// Recursive function to return gcd of a and b7// C++ program to find LCM of two numbers1 // Recursive function to return gcd of a and b6

LCM of 15 and 20 is 60
36_______138_______4 // Recursive function to return gcd of a and b9

// Recursive function to return gcd of a and b7// C++ program to find LCM of two numbers4 long2

// C++ program to find LCM of two numbers3____138_______9

// C++ program to find LCM of two numbers3

// C++ program to find LCM of two numbers3____138_______72

// C++ program to find LCM of two numbers3______138_______74

// C++ program to find LCM of two numbers3_______1_______22

LCM of 15 and 20 is 60
3 #include 3
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
4
LCM of 15 and 20 is 60
3
LCM of 15 and 20 is 60
8

// C++ program to find LCM of two numbers3______1_______9

// Recursive function to return gcd of a and b7// C++ program to find LCM of two numbers4 using1

// C++ program to find LCM of two numbers3____138_______9

// C++ program to find LCM of two numbers3

// C++ program to find LCM of two numbers3______1_______64

// C++ program to find LCM of two numbers3_______1_______15

LCM of 15 and 20 is 60
22
LCM of 15 and 20 is 60
68 // C++ program to find LCM of two numbers97

// C++ program to find LCM of two numbers3______1_______9

// Recursive function to return gcd of a and b7

LCM of 15 and 20 is 60
3 namespace0

// Recursive function to return gcd of a and b7#include 04namespace3

LCM of 15 and 20 is 60
82

namespace6_______141_______5

LCM of 15 and 20 is 60
85namespace8
LCM of 15 and 20 is 60
88

// C++ program to find LCM of two numbers3____138_______9

// C++ program to find LCM of two numbers9

 

#include 15

PHP




#include 16

#include 17

 

#include 18

// C++ program to find LCM of two numbers48

#include 20

LCM of 15 and 20 is 60
0#include 22#include 23#include 24
LCM of 15 and 20 is 60
35

LCM of 15 and 20 is 60
9

#include 27_______138_______1

LCM of 15 and 20 is 60
05#include 22 #include 31

// Recursive function to return gcd of a and b7// C++ program to find LCM of two numbers4 #include 24

LCM of 15 and 20 is 60
78

// C++ program to find LCM of two numbers3_______138_______4

LCM of 15 and 20 is 60
0#include 24 // C++ program to find LCM of two numbers09#include 22#include 23#include 22#include 44

// C++ program to find LCM of two numbers9

 

#include 46

#include 47

#include 20 #include 3#include 22#include 23#include 24

LCM of 15 and 20 is 60
35

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers3_______138_______4

LCM of 15 and 20 is 60
05#include 22 #include 59#include 22#include 23#include 24#include 63#include 24
LCM of 15 and 20 is 60
78

// C++ program to find LCM of two numbers9

 

// C++ program to find LCM of two numbers3____139_______68

// C++ program to find LCM of two numbers3_______139_______22 #include 71

// C++ program to find LCM of two numbers3_______139_______24 #include 74

// C++ program to find LCM of two numbers3_______139_______76 namespace3#include 23#include 22#include 23namespace5

namespace6_______139_______23#include 24#include 23namespace8#include 87#include 22#include 23#include 24#include 44

 

#include 15

#include 93

JavaScript




#include 94

 

#include 95

 

// Recursive function to return gcd of a and b

#include 20 #include 98

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers1 // C++ program to find LCM of two numbers2

// C++ program to find LCM of two numbers3______138_______4 // C++ program to find LCM of two numbers5

// C++ program to find LCM of two numbers4 // C++ program to find LCM of two numbers8

// C++ program to find LCM of two numbers9

 

#include 0

#include 20 using10

LCM of 15 and 20 is 60
9

// C++ program to find LCM of two numbers3_______138_______4 using1

// C++ program to find LCM of two numbers9

 

using4

using3

// C++ program to find LCM of two numbers3______140_______19

// C++ program to find LCM of two numbers3_______140_______21____141_______3

LCM of 15 and 20 is 60
82namespace5

// C++ program to find LCM of two numbers3_______1_______85namespace8

LCM of 15 and 20 is 60
88

// C++ program to find LCM of two numbers3

 

using30

 

using31

Đầu ra

LCM of 15 and 20 is 60

Thời gian phức tạp. O[log[min[a,b]]

Không gian phụ trợ. O[log[min[a,b]]

https. //youtu. be/anSfYgbo694

Vui lòng viết bình luận nếu bạn thấy bất cứ điều gì không chính xác hoặc bạn muốn chia sẻ thêm thông tin về chủ đề thảo luận ở trên

Chủ Đề