-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumber.py
More file actions
35 lines (27 loc) · 909 Bytes
/
PrimeNumber.py
File metadata and controls
35 lines (27 loc) · 909 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
from datetime import datetime
import math
class PrimeNumber():
def __init__(self):
self.primeList=[]
self.calTime=-1
def prime3mil(self):
startTime = datetime.now()
for x in range(1,3000001,2):
if ( x >1 ):
isnotprime=0
for p in range(3,math.ceil(math.sqrt(x))+1,2):
if( x % p == 0):
isnotprime += 1
if(isnotprime==0):
self.primeList.append(x)
if(x%1000001==1 or x%1000001==0):
print('million checkpoint, ', x)
self.primeList=[2]+self.primeList
self.calTime =datetime.now() - startTime
def printPrimes(self):
for i in range(100):
print(self.primeList[i])
primer = PrimeNumber()
primer.prime3mil()
primer.printPrimes()
print('\n', primer.calTime)