[Python] 7 – 10001st prime

[문제 링크]
http://projecteuler.net/problem=7

[문제 원본]
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

[문제 설명]
2에서 6번째에 해당하는 소수는 13이다. 그렇다면 10001번째 해당하는 소수는 몇인가?

[소스코드]

# problem_7.py
import custom_math
count = input("Input: ");
i = 2
while 1 : 
    if(custom_math.isPrime(i)) :
        count = count -1
    if(count == 0): 
        break
    i = i+1
print("Number is =", i)
# custom_math.py
import math
 
def isPrime(n): 
    result = True
    for i in range(2, int(math.sqrt(n)) + 1):
        if n%i == 0:
            result = False
            break
     
    return result

[결과]
Input: 10001
(‘Number is =’, 104743)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s