-
Notifications
You must be signed in to change notification settings - Fork 0
/
none-prime2.py
49 lines (41 loc) · 1.26 KB
/
none-prime2.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
def main():
def manipulate_generator(generator, n):
# Prime Function return 1 if the argument is prime
# it return 0 if the argument is none-prime
def prime(i):
for x in range(2, i):
if i%x == 0:
return 0
else:
continue
return 1
# initialize variable count
# initialize generator_list using list comprehension
count = 0
genList = [m+1 for m in range(n*2)]
# iterate through genList to print the require none-prime
# numbers in n number of times
for j in genList:
if n == 1:
print(n)
break
if prime(j) == 0:
count += 1
if count == n-1:
print(j)
break
def positive_integers_generator():
n = 1
while True:
x = yield n
if x is not None:
n = x
else:
n += 1
k = int(input())
g = positive_integers_generator()
for _ in range(k):
n = next(g)
manipulate_generator(g, n)
if __name__ == "__main__":
main()