31 lines
873 B
Python
Executable File
31 lines
873 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
|
|
class Question:
|
|
def __init__(self,i=1, l=0, n=''):
|
|
self.name=n
|
|
self.level=l
|
|
self.number=i
|
|
def __enter__(self):
|
|
print('\n' + (self.level*2)*' ' + f"-> {self.number}. : {self.name} -- Début")
|
|
return self
|
|
def __exit__(self, exc_type, exc_value, exc_traceback):
|
|
print((self.level*2)*' ' + f"<- {self.number}. : {self.name} -- Fin\n")
|
|
|
|
with Question(2):
|
|
L = [True]*31
|
|
def modifier(L, p):
|
|
if p in (0,1):
|
|
L[p] = False
|
|
else:
|
|
for i in range(2*p,len(L), p):
|
|
L[i] = False
|
|
def premiers(n):
|
|
L = [True]*(n+1)
|
|
for i in range(n):
|
|
if L[i]:
|
|
modifier(L, i)
|
|
return [i for i, premier in enumerate(L) if premier]
|
|
print(premiers(823417)[-1])
|
|
print("Donc 823417 n'est pas premier.")
|