How to find prime numbers

A simple function that allow to find first N prime numbers:

def primes(n):
    
    numbers = set(range(2, n))
    
    for j in range(2, int(np.sqrt(n))):
        numbers -= set(range(2*j, n, j))
    
    return sorted(list(numbers))

print(primes(n=100))

 

Leave a Reply

Your email address will not be published. Required fields are marked *