Sudal's Garage

Project Euler 12 본문

Programming/Project Euler - python

Project Euler 12

_Sudal 2019. 2. 27. 05:00

Question: 


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 triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

문제:


삼각수는 자연수를 더해나가면서 만들 수 있다. 예를 들어 7번째 삼각수는 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28이다. 첫 번째 삼각수부터 열 번째 삼각수까지 나열하면 다음과 같다.

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

이제 각 삼각수의 약수들을 적어보자.

 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,2

약수의 개수가 처음으로 5개 보다 커지는 삼각수는 28이다.

그렇다면 약수의 개수가 처음으로 500개 보다 커지는 삼각수는?


Solution:


1
2
3
4
5
6
7
8
9
from sympy import divisor_count
 
= 2
= 1
while divisor_count(N) <= 500:
    N += i
    i += 1
 
print(N)
cs


2019/01/29 - [Programming/python] - Module: sympy


Sympy 모듈에서 약수의 갯수를 카운팅 해주는 divisor_count method 를 이용



'Programming > Project Euler - python' 카테고리의 다른 글

Project Euler 14  (0) 2019.03.02
Project Euler 13  (0) 2019.02.28
Project Euler 11  (0) 2019.02.26
Project Euler 10  (0) 2019.02.16
Project Euler 9  (0) 2019.02.06