-
Notifications
You must be signed in to change notification settings - Fork 0
/
p7.py
43 lines (41 loc) · 854 Bytes
/
p7.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 6 20:08:20 2017
@author: Refaia
"""
'''
import math
index = 10001
indexResult = 0
i = 3
primeList = [2]
while indexResult < index - 1 :
for item in primeList :
if item >= (int(math.sqrt(i)) + 1) :
primeList.append(i)
indexResult += 1
break
if i % item == 0 :
break
if item == primeList[-1] and i % item != 0 :
primeList.append(i)
indexResult += 1
i += 2
print(primeList[indexResult])
'''
import math
def prime(n):
if n == 2 :
return True
for i in range(3, int(math.sqrt(n))+1, 2):
if n % i == 0:
return False
return True
indexResult = 3
index = 10001
i = 0
while i < index - 1:
if prime(indexResult):
i += 1
indexResult += 2
print(indexResult - 2)