this article describes the Python custom function to find the greatest common divisor and the least common multiple of the two numbers.

1. for the minimum common multiplier: the minimum common multiple of the algorithm:

minimum common multiplier = two integers the product / maximum common divisor

so we first require the maximum common divisor of two integers, and the maximum common divisor of two numbers is as follows:

2. the maximum common divisor algorithm:

(1) integer A to integer B. The remainder C = A% B

2. If C equals 0, then C is the maximum common divisor of integer and integers if not equal to 0. The remainder is 0, then the maximum common divisor

3. program code is realized as follows:

 coding:utf-8 def fun (num1, num2). In order to be divided into num1, num2 = num2, if if condition is satisfied, then the exchange of the value is exchanged between vari1 = num1 * num2, and the product of two integers is calculated, and the minimum common multiplier vari2 = num1% num2 num1 is calculated, and the remainder of the 2 integers is taken to determine whether the remainder is 0, if not 0, then enter The next calculation num2 = vari2 vari2 = num1% num2 num2 = 0 integers after the re assignment until vari2 is equal to 0, and the maximum common divisor gets out of the cyclic vari1 / = num2, and obtains the minimum common multiple print ("the maximum common divisor is%d"%). Output print ("minimum common multiple:%d"% vari1) output fun (6, 9) 

operation results: the maximum common divisor of

is the minimum common multiple of 3
: 18

. 42111571 "alt=" ">

PS: Here we recommend a site related online tool for you to refer to:

more interested in Python related content can see the site topic: "Python mathematical computing skills summary ", "Python data structure and algorithm tutorial", "summary function use skill summary" /a>, "Python string manipulation skills summary ", "Python introductory and advanced classic tutorial " and "

you may be interested in the article:


This concludes the body part

This paper fixed link: | Script Home | +Copy Link

Article reprint please specify:Python custom function to achieve two numbers of the greatest common divisor, the smallest common multiple examples | Script Home

You may also be interested in these articles!