In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to find the maximum common divisor and the minimum common multiple in python". The content in the article is simple and clear, and it is easy to learn and understand. now please follow the editor's train of thought to study and learn "how to find the maximum common divisor and the minimum common multiple in python".
First, find the greatest common divisor
The algorithm for finding the maximum common divisor by toss and turn division is as follows:
Two positive integers an and b (a > b) whose greatest common divisor is equal to the largest common divisor between the remainder c and b of a divided by b. For example, 10 and 25 25 divided by 10 quotient 2 over 5, then the maximum common divisor of 10 and 25 is equal to the maximum common divisor of 10 and 5.
The specific code is as follows:
Def gongyue (a, b): "" Euclid algorithm-Division: param a: the first number: param b: the second number: return: the greatest common divisor "" # if the final remainder is the 0 common divisor, while (bounded zero): temp = a% b a = b = temp return a
Second, find the least common multiple
After finding the maximum common divisor of aformab, the least common multiple of the two numbers is calculated by using gongbei (aforb) = (aforb) / gongyue (aforb):
# find the least common multiple of two numbers def gongbei (aMaginb): return a * b / gongyue (aforme b)
Knowledge points to add:
1. An algorithm for finding the least common multiple:
Least common multiple = product of two integers / maximum common divisor
So we first ask for the maximum common divisor of two integers, and the idea of finding the maximum common divisor of two numbers is as follows:
two。 Algorithm for finding the maximum common divisor:
The ① integer A rounds the integer B, and the remainder is represented by the integer C. for example: C = A% B.
② if C equals 0, then C is the greatest common divisor of integers An and B.
③ if C is not equal to 0, assign B to A, C to B, and then take 1, 2 steps until the remainder is 0, then you can get the greatest common divisor.
Thank you for your reading, the above is the content of "how to find the maximum common divisor and the minimum common multiple of python". After the study of this article, I believe you have a deeper understanding of how to find the maximum common divisor and the minimum common multiple of python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.