일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 상합
- algeomath
- 프로젝트 오일러
- 몬테카를로
- 이항분포
- 오일러
- 삼각함수의그래프
- 파이썬
- 재귀함수
- Geogebra
- 구분구적법
- 시뮬레이션
- 수학탐구
- counting sunday
- 알지오매스
- 프랙탈
- 블록코딩
- 피타고라스 정리
- 지오지브라
- 작도
- 하합
- 정오각형
- project euler
- 확률실험
- 제곱근의뜻
- 큰수의법칙
- python
- 리만합
- java
- 큰 수의 법칙
Archives
- Today
- Total
이경수 선생님의 수학실험실
Problem 44(Pentagon numbers) 본문
Problem 44(Pentagon numbers)
Pentagonal numbers are generated by the formula, \(P_{n}=\frac{n(3n−1)}{2}\). The first ten pentagonal numbers are:
\(1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...\)
It can be seen that \(P_{4} + P_{7} = 22 + 70 = 92 = P_{8}\). However, their difference, \(70 − 22 = 48\), is not pentagonal.
Find the pair of pentagonal numbers, \(P_{j}\) and \(P_{k}\), for which their sum and difference are pentagonal and \(D = |P_{k} − P_{j}|\) is minimised; what is the value of \(D\)?
In Python:
import time
import math
startTime = time.time()
diffList = []
for i in range(1, 10 ** 4):
val1 = 0
for j in range(0, 10 ** 4):
val1 += 3 * (i + j) + 1
if math.sqrt(1 + 24 * val1) % 6 == 5:
val2 = i * (3 * i - 1) + val1
if math.sqrt(1 + 24 * val2) % 6 == 5:
diffList.append(val1)
print(min(diffList))
print(time.time() - startTime, "seconds")
Run time: 59.95046591758728 seconds
In Python:
import time
startTime = time.time()
i = 2
check = 0
pentagonList = [1]
while True:
pentagon = i * (3 * i - 1) // 2
for j in pentagonList:
k = pentagon - j
if k in pentagonList:
if abs(j - k) in pentagonList:
print(abs(j - k));
check = 1
break
pentagonList.append(pentagon)
if check == 1:
break
i += 1
print(time.time() - startTime, "seconds")
Run time: 59.71640586853027 seconds
In Python:
import time
import math
def ispentagon(n):
if math.sqrt(1 + 24 * n) % 6 == 5:
return True
else:
return False
startTime = time.time()
i = 2
check = 0
pentagonList = [1]
while True:
pentagon = i * (3 * i - 1) // 2
for j in pentagonList:
k = pentagon - j
if ispentagon(k) and ispentagon(abs(j - k)):
print(abs(j - k));
check = 1
break
if check:
break
else:
pentagonList.append(pentagon)
i += 1
print(time.time() - startTime, "seconds")
Run time: 1.6193530559539795 seconds
Solution: 5482660
'Project Euler' 카테고리의 다른 글
Problem 46(Goldbach's other conjecture) (0) | 2019.08.15 |
---|---|
Problem 45(Triangular, pentagonal, and hexagonal) (0) | 2019.08.15 |
Problem 43(Sub-string divisibility) (0) | 2019.07.24 |
Problem 42(Coded triangle numbers) (0) | 2019.07.24 |
Problem 41(Pandigital prime) (0) | 2019.06.16 |
Comments