online笔试题总结

1.输入n求1到n的最小公倍数(关键在于所有的非质数都可以由若干质数相乘得到,把最小公倍数写成质数相乘的形式)

n = int(input())
re = []
ans = 1
def zs(a):
    count = 0
    for i in range(1, a+1):
        if a%i == 0:
            count += 1
    return count
for i in range(1, n+1):
    if zs(i) == 2:
        re.append(i)
for i in range(len(re)):
    cnt = 1
    tar = re[i]
    while tar <= n:
        cnt += 1
        tar = re[i]**cnt
    re[i] = re[i]**(cnt-1)
for i in re:
    ans *= i
print(ans)

你可能感兴趣的:(online笔试题总结)