Here, we will be framing code for finding the least multiple of a number x from a given set of numbers (set of 5 numbers in this program, and it could be many numbers as per the problem).
在这里,我们将使用成帧代码从给定的一组数字中找到数字x的最小倍数 (此程序中一组5个数字,根据问题可能是许多数字)。
There will be a problem while you go to find the least multiple.
当您寻找最小倍数时会有问题。
There are many ways of doing this but this time, we have to thought of most computationally efficient algorithm to do so.
有很多方法可以做到这一点,但是这一次,我们必须考虑到计算效率最高的算法。
Using for loop and checking every time might be the thing which works better than other approached. But it about checkings of the least value to be considered for comparing.
每次使用for循环和检查可能是比其他方法更好的方法。 但是它涉及要考虑比较的最小值的检查。
So let's work it out.
因此,让我们解决吧。
Following is the code for such problem,
以下是解决此问题的代码,
n = 0
num = 0
minnum = 13
j = 0
x = int(input("Enter the num of which you want to find least multiple: "))
while n<5:
num = int(input("Enter your number : "))
if num%x == 0:
j = j + 14
if j == 14:
minnum = num
if num < minnum:
minnum = num
else:
print("Not multiple")
n += 1
if minnum%x == 0:
print("The maximum multiple :",minnum)
else:
print("No multiple there")
Output
输出量
翻译自: https://www.includehelp.com/python/find-the-least-multiple-from-given-n-numbers.aspx