premier.py

Created by alexandrebret-84

Created on May 01, 2022

643 Bytes


from math import sqrt

def is_prime(n):
    if n < 2:
        return False
    for nombre in range(2, n):
        if n%nombre == 0:
            return False
    return True
    
def liste_prime(n):
    nb = 2
    liste_p = []
    while len(liste_p) != n:
        if is_prime(nb) == True:
            liste_p.append(nb)
        nb += 1
    return liste_p
    
#print(liste_prime(100))

def is_prime2(n):
    if n < 2:
        return False
    for nombre in range(2, n):
        if n%nombre == 0 and nombre <= sqrt(n):
            temp = is_prime2(nombre)
            if temp == True:
                return False
    return True

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 cookies policy.