본문 바로가기

Euler Project

Problem 4 - Find the largest palindrome made from the product of two 3-digit numbers. 링크 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99. Find the largest palindrome made from the product of two 3-digit numbers. python ans = 0 for i in range(100, 1000): for j in range(i, 1000): n = i * j sn = str(n) if sn == sn[::-1] and n > ans: ans = n print ans python - 1 line print max([x*y for x in range(900,1.. 더보기
Problem 3 - Find the largest prime factor of a composite number. 링크 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? python n = 600851475143 d = 3 ans = 0 while n > 1: while n % d == 0: n = n / d ans = d d = d + 2 print ans bash Shell echo 600851475143|factor 더보기
Problem 2 - Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million. 링크 Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find the sum of all the even-valued terms in the sequence which do not exceed four million. python a = 0 b = 1 res = 0 while a 더보기
Problem 1 - Add all the natural numbers below one thousand that are multiples of 3 or 5. 링크 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. python 1 sum = 0 for i in range(1, 1000): if i % 3 == 0 or i % 5 == 0: sum += i print sum python 2 print sum([x for x in range(1000) if x % 3 == 0 or x % 5 == 0]) 더보기