Python Finds the Maximum Common Number and the Minimum Common Multiplier of Two or Three Positive Integers

Topic: Find the maximum common number and the minimum common multiple of two positive integers.
Basic requirements: 1. Good program style (using custom annotation template), two or more algorithms to solve the maximum common divisor problem, provide friendly input and output.
Increase requirements:
1. More than three algorithms are used to solve the problem of the maximum common divisor of two positive integers.
2. Find the maximum common number and the minimum common multiple of three positive integers.

The source code is as follows:

# Finding the Maximum Common Number by Rotating Phase Division
#
# a = int(input("Please enter the value of a:")
# b = int(input("Please enter the value of b:")
# c = 0
# if a<b:
#     c = a
#     a = b
#     b = c
# while a%b!=0:
#     c = a%b
#     a = b
#     b = c
# print("Maximum common denominator:"+str(b)))






# Finding the Maximum Common Number by Subtraction


# a = int(input("Please enter the value of a:")
# b = int(input("Please enter the value of b:")
# c = 0
# if a<b:
#     c = a
#     a = b
#     b = c
# while a-b!=0:
#     c = a-b
#     a = b
#     b = c
# print("Maximum common denominator:"+str(b)))





#The Third Method to Find the Maximum Common Number

#Enter two numbers and loop out the number between the minimum values of one and two numbers. When the number can be divided by a and b at the same time, save these numbers in the array i[]
#sort() is used to sort array I from small to large, and i[-1] is used to output the maximum value of array I [], i.e. the maximum common divisor.

# a = int(input("Please enter the value of a:")
# b = int(input("Please enter the value of b:")
# if a>b:
#     t = a
#     a = b
#     b = t
# for n in range(1,a+1):
#     if a%n==0 and b%n==0:
#         i = [n]
#         i.sort()
# print("Maximum common denominator:"+str(i[-1])))
#
#
#
#
#



#Finding the Maximum Common Number of Three Numbers: Finding the Maximum Common Number of Two Numbers, then Finding the Maximum Common Number of Two Numbers and the Maximum Common Number of Another Number
# a = int(input("Please enter the value of a:")
# b = int(input("Please enter the value of b:")
# c = int(input("Please enter the value of c:")
# if a>b:
#     t = a
#     a = b
#     b = t
# for n in range(1,a+1):
#     if a%n==0 and b%n==0:
#         i = [n]
#         i.sort()
# m = i[-1]
# Print ("the maximum common denominator of a and b is:" + str(m)))
# if m>c:
#     l = m
#     m = c
#     c = l
# for n in range(1, m+1):
#     if m%n == 0 and c%n == 0:
#         p = [n]
#         p.sort()
# Print ("the maximum common number of a B C is:" + str(p[-1])
#
#



# The First Method of Finding the Minimum Common Multiplier
# Find the smallest common multiple of three numbers, cycle out the multiples of three numbers, find the same number, put it in the array, output the smallest value.
# a = int(input("Please enter the value of a:")
# b = int(input("Please enter the value of b:")
# c = int(input("Please enter the value of c:")
# d = a * b * c
# m = []
# n = []
# o = []
# for i in range(1, d + 1):
#     if i % a == 0:
#         m.append(i)
# Print ("the common multiple of a:" + str(m)))
# for j in range(1, d + 1):
#     if j % b == 0:
#         n.append(j)
# Print ("The common multiple of B is:" + str(n)))
# for k in range(1, d + 1):
#     if k % c == 0:
#         o.append(k)
# print("c Common multiple:" + str(o))  # The common multiple of abc is stored in three arrays
# f = []
# for i in m:
#     if (i in n):
#         if (i in o):
#             f.append(i)
#             f.sort()
#             Print ("all common multiples of a B c:" + str(f[0])


# The Second Method of Finding the Minimum Common Multiplier
# To find the minimum common multiple of three numbers, first set a number=1, and then judge the balance of number to abc. When the balance is zero at the same time, jump out of the cycle and output the number. Otherwise, continue to cycle number+=1.
a = int(input("Please input a Value:"))
b = int(input("Please input b Value:"))
c = int(input("Please input c Value:"))
number = 1
while True:
    if number%a==0 and number%b==0 and number%c==0:
        print("abc Minimum common multiple:" + str(number))
        break
    else:
        number+=1

Algorithmic ideas:
The methods for finding the maximum common divisor of two integers are as follows:
1. Algorithmic ideas: rolling phase division
2. Algorithmic ideas: rolling subtraction
3. Algorithmic ideas: Input two numbers, and circle out the number between the minimum values of one and two numbers. When the number can be divided by a and b at the same time, these numbers are saved in the array i [], sort() function is used to sort the array i [] from small to large, and then output i[-1], that is, the maximum common divisor.

The method of finding the greatest common divisor of three positive integers:
1. Algorithmic ideas: On the basis of the above method 3, the calculation of the maximum common divisor between two pairs is carried out.

Method of finding the minimum common multiple of three positive integers:
1. Algorithmic ideas: First, output three multiples separately, then find out the same number in the three arrays, put these numbers in a new array, sort() sort them and output them.
2. Algorithmic ideas: first set a number=1, then while True to cycle, judge the number of abc surplus, when their remainder is zero at the same time, break and print out the number value, otherwise number+=1

The flow chart of the system for calculating the maximum common divisor is as follows:

The flow chart of the system for calculating the minimum common multiple is as follows:

Posted by Drezek on Tue, 14 May 2019 07:39:20 -0700