일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
Tags
- 수학탐구
- 제곱근의뜻
- 구분구적법
- 재귀함수
- 몬테카를로
- 작도
- 프로젝트 오일러
- 큰 수의 법칙
- 블록코딩
- 프랙탈
- 정오각형
- 상합
- 시뮬레이션
- counting sunday
- algeomath
- 하합
- java
- 피타고라스 정리
- project euler
- Geogebra
- 삼각함수의그래프
- 리만합
- python
- 확률실험
- 알지오매스
- 이항분포
- 파이썬
- 큰수의법칙
- 오일러
- 지오지브라
Archives
- Today
- Total
이경수 선생님의 수학실험실
Problem 49(Prime permutations) 본문
Problem 49(Prime permutations)
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.
There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.
What 12-digit number do you form by concatenating the three terms in this sequence?
In Python:
import time
import math
def seive(n):
i = 2
primecodeList =[1 for i in range(1, n + 1)]
primecodeList[0] = 0
primeList = []
while i < n + 1:
if primecodeList[i - 1] == 1:
primeList.append(i)
for j in range(2, n // i + 1):
primecodeList[i * j - 1] = 0
i += 1
return primeList
def ispermutation(i, j, k):
stri = sorted(str(i))
strj = sorted(str(j))
strk = sorted(str(k))
if stri == strj and strj == strk:
return True
startTime = time.time()
primeList = []
for prime in seive(10 ** 4):
if math.log10(prime) > 3:
primeList.append(prime)
for i in range(0, len(primeList)):
for k in range(0, i):
j = (primeList[i] + primeList[k]) // 2
if j in primeList and ispermutation(primeList[i], j, primeList[k]):
print(str(primeList[k]) + str(j) + str(primeList[i]))
print(time.time() - startTime, "seconds")
Run time: 8.202334880828857 seconds
In Python:
import time
import math
def seive(n):
i = 2
primecodeList =[1 for i in range(1, n + 1)]
primecodeList[0] = 0
primeList = []
while i < n + 1:
if primecodeList[i - 1] == 1:
for j in range(2, n // i + 1):
primecodeList[i * j - 1] = 0
if math.log10(i) > 3:
primeList.append(i)
i += 1
return primeList
def ispermutation(i, j):
stri = sorted(str(i))
strj = sorted(str(j))
if stri == strj:
return True
startTime = time.time()
primeList = seive(10 ** 4)
for i in range(0, len(primeList)):
for k in range(0, i):
if ispermutation(primeList[i], primeList[k]):
j = (primeList[i] + primeList[k]) // 2
if j in primeList and ispermutation(primeList[i], j):
print(str(primeList[k]) + str(j) + str(primeList[i]))
print(time.time() - startTime, "seconds")
Run time: 0.8857400417327881 seconds
Solution: 296962999629
'Project Euler' 카테고리의 다른 글
Problem 51(Prime digit replacements) (0) | 2019.08.18 |
---|---|
Problem 50(Consecutive prime sum) (0) | 2019.08.18 |
Problem 48(Self powers) (0) | 2019.08.16 |
Problem 47(Distinct primes factors) (0) | 2019.08.15 |
Problem 46(Goldbach's other conjecture) (0) | 2019.08.15 |
Comments