eratosthene.py

Created by christian-mercat

Created on February 03, 2024

330 Bytes

Crible d’Eratosthène permettant de trouver les nombres premiers jusqu’à une taille donnée


era = []
taille=100 # <taille
era.append(False) # era[0]=False
era.append(False) # era[1]=False
for p in range(2,taille):
  era.append(True)
p=2
while p*p < taille :
  if era[p]:
   mult=p*p; 
   while mult < taille :
     era[mult]=False;
     mult += p;
  p +=1
for p in range(1,taille):
  if era[p]: print(p)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.