-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimeFinder.py
119 lines (105 loc) · 3.58 KB
/
primeFinder.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def start(mode="prime", position_number=0, position2_number=0, position3_number=0):
import math
z = 80 # root: math.sqrt(y)
def isDivisible(number,divisor):
if number % divisor == 0:
return True
return False
def is_prime_number(x,pmode="prime"):
if pmode == "prime":
if x >= 2:
for y in range(2,x):
if not ( x % y ): # x % y == 0
return False
else:
return False
return True
elif pmode == "position":
for z in range(2):
if x >= 2:
for y in range(2,x):
if not ( x % y ):
return False
else:
return False
if z == 0:
x = x//position_number
return True
elif pmode == "position2":
for z in range(2):
if x >= 2:
for y in range(2,x):
if not ( x % y ):
return False
else:
return False
if z == 0:
try:
x = x//position_number
except:
pass
x += 10
x = x//position2_number
return True
elif pmode == "position3":
for z in range(2):
if x >= 2:
for y in range(2,x):
if not ( x % y ):
return False
else:
return False
if z == 0:
try:
x = x//position_number
except:
pass
x += position_number*2
try:
x = x//position2_number
except:
pass
x += position2_number*3
x = x//position3_number
return True
primes = []
y = 4241
if mode == "prime":
for x in range(y):
print(x)
if isDivisible(x, z) is True:
primes.append("\n")
if is_prime_number(x) is True:
primes.append("#")
else:
primes.append("0")
elif mode == "position":
for x in range(y):
print(x)
if isDivisible(x, z) is True:
primes.append("\n")
if is_prime_number(x,"position") is True:
primes.append("#")
else:
primes.append("0")
elif mode == "position2":
for x in range(y):
print(x)
if isDivisible(x, z) is True:
primes.append("\n")
if is_prime_number(x,"position2") is True:
primes.append("#")
else:
primes.append("0")
elif mode == "position3":
for x in range(y):
print(x)
if isDivisible(x, z) is True:
primes.append("\n")
if is_prime_number(x,"position3") is True:
primes.append("#")
else:
primes.append("0")
with open("primes.txt", "w") as p:
for x in primes:
p.write(x)