-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestfunc.py
More file actions
40 lines (31 loc) · 967 Bytes
/
Testfunc.py
File metadata and controls
40 lines (31 loc) · 967 Bytes
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
import math
from datetime import datetime
is_prime = list()
limit = 300000000
is_prime = [False] * (limit + 1)
primeList=[2,3]
startTime = datetime.now()
for x in range(1,int(math.sqrt(limit))+1):
for y in range(1,int(math.sqrt(limit))+1):
n = 4*x**2 + y**2
if n<=limit and (n%12==1 or n%12==5):
# print "1st if"
is_prime[n] = not is_prime[n]
n = 3*x**2+y**2
if n<= limit and n%12==7:
# print "Second if"
is_prime[n] = not is_prime[n]
n = 3*x**2 - y**2
if x>y and n<=limit and n%12==11:
# print "third if"
is_prime[n] = not is_prime[n]
for n in range(5,int(math.sqrt(limit))):
if is_prime[n]:
for k in range(n**2,limit+1,n**2):
is_prime[k] = False
for n in range(5,limit):
if is_prime[n]: primeList.append(n)
calTime =datetime.now() - startTime
for i in range(20):
print(primeList[i])
print(calTime)