반응형
소수를 크기 순으로 나열하면 2, 3, 5, 7, 11, 13, ... 과 같이 됩니다.
이 때 10,001번째의 소수를 구하세요.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
def is_prime_num(num) : | |
for i in range(2, int(num**0.5) + 1): | |
if num % i==0: | |
return False | |
return True | |
def find_prime_num(seq_range_to) : | |
num = 3 | |
prime_seq = 1 | |
prime_num = 0 | |
while prime_seq < seq_range_to : | |
if is_prime_num(num) == True : | |
prime_seq += 1 | |
prime_num = num | |
num += 2 | |
return prime_num | |
print(find_prime_num(10001)) |
primesieve 모듈을 받으면 미친듯이 쉽게 짤 수 있다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from primesieve import nth_prime | |
print(nth_prime(10001)) |
반응형
'개발 > 알고리즘 문제' 카테고리의 다른 글
[Project Euler 09] a + b + c = 1000 이 되는 피타고라스 수 (0) | 2016.03.01 |
---|---|
[Project Euler 08] 1000자리 숫자 안에서 이어지는 5자리 숫자의 곱 중 최대값은? (0) | 2016.03.01 |
[Project Euler 06] 1부터 100까지 "제곱의 합"과 "합의 제곱"의 차는? (0) | 2016.03.01 |
[Project Euler 05] 1 ~ 20 사이의 어떤 수로도 나누어 떨어지는 가장 작은 수 (0) | 2016.03.01 |
[Project Euler 04] 세자리 수를 곱해 만들 수 있는 가장 큰 대칭수 (0) | 2016.03.01 |
댓글