Python程序从给定的N个数中查找最小倍数

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

输出量

find least mulitple from given N numbers in Python

翻译自: https://www.includehelp.com/python/find-the-least-multiple-from-given-n-numbers.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值