Showing posts with label algorithm. Show all posts
Showing posts with label algorithm. Show all posts

19 August, 2010

projecteuler.net - Q5

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

i = 1
for k in range(1,21):
    if i%k > 0:
        for j in range(1,21):
            if (i*j) % k == 0:
                i *= j
                break
print i

02 July, 2010

算法之美:求一个数n的最大质因数(Python)

n=600851475143
d=2
while d < n/d:
    if n%d==0:
        n/=d
    else:
        d+=1
print n