일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 오일러
- counting sunday
- project euler
- 블록코딩
- 하합
- 피타고라스 정리
- 파이썬
- 프랙탈
- 정오각형
- 작도
- 상합
- 지오지브라
- java
- 이항분포
- 시뮬레이션
- 제곱근의뜻
- 알지오매스
- 큰 수의 법칙
- 삼각함수의그래프
- 리만합
- 구분구적법
- python
- 재귀함수
- 수학탐구
- 확률실험
- 큰수의법칙
- Geogebra
Archives
- Today
- Total
이경수 선생님의 수학실험실
Problem 47(Distinct primes factors) 본문
Problem 47(Distinct primes factors)
The first two consecutive numbers to have two distinct prime factors are:
\(14 = 2 \times 7\)
\(15 = 3 \times 5\)
The first three consecutive numbers to have three distinct prime factors are:
\(644 = 2^{2} \times 7 \times 23 \)
\(645 = 3 \times 5 \times 43 \)
\(646 = 2 \times 17 \times 19 \).
Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?
In Python:
import time
def numprimefactor(n):
i = 2
count = 0
while True:
if n % i == 0:
count += 1
while n % i == 0:
n /= i
if n == 1:
return count
i += 1
startTime = time.time()
i = 2
count = 0
while True:
if numprimefactor(i) == 4:
count += 1
if count == 4:
break
else:
count = 0
i += 1
print (i - 3)
print(time.time() - startTime, "seconds")
Run time: 282.98886609077454 seconds
In Python:
import time
import math
def numprimefactor(n, l):
count = 0
for i in l:
if n % i == 0:
count += 1
while n % i == 0:
n /= i
if n == 1:
return count
i += 1
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
startTime = time.time()
i = 2
count = 0
primeList = seive(10 ** 3)
while True:
if numprimefactor(i, primeList) == 4:
count += 1
if count == 4:
break
else:
count = 0
i += 1
print (i - 3)
print(time.time() - startTime, "seconds")
Run time: 3.5005621910095215 seconds
Solution: 134043
'Project Euler' 카테고리의 다른 글
Problem 49(Prime permutations) (0) | 2019.08.16 |
---|---|
Problem 48(Self powers) (0) | 2019.08.16 |
Problem 46(Goldbach's other conjecture) (0) | 2019.08.15 |
Problem 45(Triangular, pentagonal, and hexagonal) (0) | 2019.08.15 |
Problem 44(Pentagon numbers) (0) | 2019.07.24 |
Comments