Euler第五题:
求1到20各数的最小公倍数。
目前我用的方法是按照短除法求最小公倍数的方法做的。Euler给出的方法虽然原理基本搞懂,但是编程还没有实现。
——————————————————————————————————-
def primeNumber(k):
primes=[2,3,5,7,11,13,17,19]
number=21
while number<k:
flag=True
for prime in primes:
if number%prime==0:
flag=False
break
if flag:
primes.append(number)
number=number+2
return primes
def smallestMulti(z):
dividends=[]
for i in range(z):
dividends.append(i+1)
print(“{0}n{1}”.format(dividends,”–“*2*len(dividends)))
dividers=primeNumber(z)
print(“{0}n{1}”.format(dividers,”–“*2*len(dividers)))
divisors=[]
for divider in dividers:
flag=True
while flag:
for i in range(len(dividends)):
if dividends[i]%divider==0:
flag=True
divisors.append(divider)
break
else:
flag=False
for i in range(len(dividends)):
if dividends[i]%divider==0:
dividends[i]=dividends[i]//divider
# print(dividends)
print(“{0}n{1}”.format(divisors,”–“*2*len(divisors)))
answer=1
for divisor in divisors:……
阅读全文