Last active
June 3, 2019 17:57
-
-
Save eloidrai/f9953a149d0bcb5e24d58875b52ddb2d to your computer and use it in GitHub Desktop.
Fonctions sur les nombres premiers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def crible_eratosthene(n_max): | |
liste = list(range(1, n_max+1)) | |
for table in range(2, int(math.sqrt(n_max))+1): | |
if liste[table-1]!=0: | |
for n in range(2*table, n_max+1, table): | |
liste[n-1]=0 | |
return [i for i in liste if i!=0 and i!=1] | |
def est_premier(n): | |
if n==1: | |
return False | |
elif n==2: | |
return True | |
for diviseur in range(2, math.ceil(math.sqrt(n))+1): | |
if n%diviseur==0: | |
return False | |
return True | |
def prochain_premier(n): | |
n+=1 | |
while not est_premier(n): | |
n+=1 | |
return n | |
def facteurs(n): | |
l=[] | |
d=2 | |
if n==0 or n==1: | |
return n | |
while n!=1: | |
while n%d==0: | |
l.append(d) | |
n=n//d | |
d=prochain_premier(d) | |
return l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment