본문 바로가기

전체 글

(48)
[Project Euler]12. Highly divisible triangular number [문제] The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28 We can see that 28 is the first tria..
[Project Euler]11. Largest product in a grid [문제] In the 20×20 grid below, four numbers along a diagonal line have been marked in red. 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 24 47 32..
[Project Euler]10. Summation of primes [문제] The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. [풀이] result = list(range(3,2000000,2)) for i in result: result = list(filter(lambda a: not(a%i==0 and a!=i) , result)) print(sum(result)) ''' 완전 비효율적인 코드인 걸 안다... 며칠을 고민을 해봐도 답이 영 안나온다. 구글링을 해본 결과 에라토스테네스의 체 방식을 이용해서 푸는 것이 일반적인 풀이 방식이라고 한다. 구글링을 하면서 본 코드들이 자꾸 머리속에 떠다녀서 나중에 다시 풀어보기로 했다.. '''
[Project Euler]9. Special Pythagorean triplet [문제] A Pythagorean triplet is a set of three natural numbers, a
[Project Euler]8. Largest product in a series [문제] The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 6222989342338030813533627661428..
[Project Euler]7. 10001st prime [문제] By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? [풀이] def find_primeNumber(n): if n==1: result = 2 else: num = 4 count = 2 result = 3 while count
[Project Euler]6. Sum square difference [문제] The sum of the squares of the first ten natural numbers is,12+22+...+102=385 The square of the sum of the first ten natural numbers is, (1+2+...+10)2=552=3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025−385=2640. Find the difference between the sum of the squares of the first one hundred natural numbers and the squar..
[Project Euler]5. Smallest multiple [문제] 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? [풀이] total = 1 for i in range(1,21): result = [] for j in range(2,21): if total %j==0 and i%j==0: while total%j==0 and i%j==0: i=int(i/j) total=int(total/j) result.append(j) for a in resul..