---
title: "No.7 The 10001st prime number"
author: "诗意的栖居"
date: "2012-08-23T16:16:15Z"
tags: []
categories: ["编程语言"]
slug: "no-7-the-10001st-prime-number"
draft: false
lastmod: "2012-08-23T16:16:15Z"
id: 1659960
url: "https://fyan.iteye.com/blog/1659960"
---

Q:
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?

A:
import math
import time

t1 = time.time()

def getNum(n):
    #for i in range(2,int(n/2)):
    for i in range(2,int(math.sqrt(n))+1):
        if n % i == 0:
            return 0
    return n

count = 2
i = 5

while count < 100001:
    if getNum(i):
        count += 1
    i += 2

print "The 10001st prime number is %d" %(i - 2)

t2 = time.time()
print "time used: %s" %(t2 - t1)