- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpython_primes.py
More file actions
Latest commit
90 lines (69 loc) · 1.96 KB
/
Copy pathpython_primes.py
File metadata and controls
90 lines (69 loc) · 1.96 KB
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
# -*- coding: utf-8 -*-
"""
Programa desarrollado por el Licenciado César Cordero Rodríguez.
Bajo licencia GPLv3.
Puede ser modificado, copiado y distribuido.
Se desarrolló con fines educativos.
"""
importtime
importos
defwrite_file(value, way, file_name):
os.system("echo "+str(value) +" "+str(way) +" "+str(file_name))
defprimes(i, count, total_found):
write_file(str(i), ">", "primos.last")
write_file(str(total_found+count), ">", "total_primes.found")
defcalculate_primes():
found=0
i=0
try:
number=open("number_of_primes.to_find", "r")
top=int(number.read())
number.close()
except:
top=100
write_file(str(top), ">", "number_of_primes.to_find")
try:
total_found_file=open("total_primes.found", "r")
total_found=int(total_found_file.read())
total_found_file.close()
except:
total_found=0
try:
last=open("primos.last", "r")
last_n=int(last.read())
last.close()
except:
last_n=1
i=last_n
iftotal_found>0:
count=-1
else:
count=0
whileTrue:
ifi==1:
count+=1
print("Prime found = "+str(i))
write_file(str(i), ">>", "primos.list")
primes(i, count, total_found)
i+=1
continue
found=2
forjinrange(2, i):
ifi%j==0:
found+=1
break
iffound==2:
count+=1
print("Prime found = "+str(i))
write_file(str(i), ">>", "primos.list")
primes(i, count, total_found)
ifcount==top:
primes(i, count, total_found)
break
i+=1
print("Total primes "+str(total_found+count))
inicio=time.time()
calculate_primes()
final=time.time()
print("Final "+str((final-inicio)))
print("Primes Python")