-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps1a.py
52 lines (46 loc) · 1.08 KB
/
ps1a.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
44
45
46
47
48
49
50
51
52
#Problem set 1a
#Name Madhavi Desai
#Time 12:20PM
nextOdd = 3
numList = []
primeList = []
divisior = 1
countDivisior = 0
primeCount = 0
column_pad = 6
max_column = 6
column = 1
#Create an array of odd numbers from 1 to 10000
while(nextOdd < 10000):
if(nextOdd%2 != 0):
numList.append(nextOdd)
nextOdd = nextOdd + 1
#Initialize n with first number from odd numbers list.
n = numList[0]
#Since we know that 2 is prime number, add it to primeList array.
primeList.append(2)
print str(2).center(column_pad),
for n in numList:
#Find number of divisiors for number n.
while(divisior <= n):
if(n%divisior == 0):
countDivisior = countDivisior + 1
divisior = divisior + 1
#If there are only 2 divisiors for number n then it is
#prime number and add it to the primeList array.
if(countDivisior == 2):
primeList.append(n)
print str(n).center(column_pad),
column += 1
if column == max_column:
print
column = 1
primeCount = primeCount + 1
lastPrime = n
divisior = 1
countDivisior = 0
if (primeCount == 999):
break
print
print
print '1000th prime number is',lastPrime