in this article, Python is based on recursive and non recursive algorithms for finding the greatest common divisor and the least common multiple of the two numbers. Share to everyone for your reference, specific as follows:

the maximum common divisor and the minimum common multiple of the concept of everyone is very familiar with, here is not much said, today this is because when the problem encountered, so it is written down as a record, also hope to help others, the next is the code

! /usr/bin/env PY Thon #coding:utf-8 from fractions import GCD not recursively implement def gcd_test_one (a, b): if a. Print'Number is wrong!! def gcd_test_two recursive def gcd_test_two (a, b): if a> b: a. Print gcd_test_one (6,24) print gcd_test_one (0,24) print '- -- - --- print gcd_test_two (12,24) print. - -- 'print gcd_test_three (12,24) print gcd_test_three (12,8)

results are as follows:

12

4

. ----------------------------------------------------

12

4

**PS: here is a new online tool for you to refer to: **

http://tools.jb51.net/jisuanqi/gbs_gys_calc

more readers interested in Python related content can view the site theme: "Python mathematical computing skills summary ", < a disabilities "data structure and algorithm tutorial < "/a>", "Python function uses skill summary ", "Python string manipulation skills summary ", "

#### you may be interested in the article:

- Python realization of the maximum common divisor for the minimum common multiple of three positive integers The realization method of solving the maximum common divisor "target=" _blank "> the realization method of using Python to solve the maximum common divisor
- Python realizes the maximum common divisor and the number of judging elements." A method for solving the maximum common divisor by dividing the method "target=" _blank ">Python based on the method of solving the maximum common divisor of the
- Python" _blank ">Python based on the more phase reduction technique to achieve the maximum common divisor An example of the maximum common divisor algorithm for
- Python implementation of the maximum common divisor algorithm example
- Python search for two methods of median of sequence tables [based on merge algorithm]
- Python implementation of a simple solution of a given integer. An example of the quality factor algorithm
- Python implementation of the first 5 examples of the
- .
This concludes the body part

This paper fixed link:http://www.script-home.com/python-based-on-recursive-and-non-recursive-algorithm-for-finding-the-greatest-common-divisor-and-least-common-multiple-of-two-numbers.html | Script Home |** +Copy Link **

Article reprint please specify:Python based on recursive and non recursive algorithm for finding the greatest common divisor and least common multiple of two numbers | Script Home