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:

(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:

- Python implementation using the maximum common divisor for the minimum common multiple of three positive integers Recursive and non recursive algorithms for two maximum common divisors and minimum common multiple examples "target=" _blank ">Python based on recursion and non recursive algorithm for the maximum common divisor of two numbers, the minimum common multiple example
- using Python to solve the maximum common use of Python
- Python realizes the maximum common divisor and the method of judging prime number
- Python based on the method of more phase impairment to achieve the maximum common divisor
- Python implementation
- Python implementation of the minimum common multiple algorithm example
- Python lookup two methods of median of sequence tables [based on merge algorithm]
- Python implementation of a simple solution of a given integer's quality factor algorithm example
- Python" is to find the first 5 algorithms of the algorithm,

This paper fixed link:http://www.script-home.com/python-custom-function-to-achieve-two-numbers-of-the-greatest-common-divisor-the-smallest-common-multiple-examples.html | 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