Ad
Code
Diff
  • # We can use Sieve of Eratosthenes for fast search of prime numbers
    # https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
    
    def primemaker(x):
        # Edge cases
        if x < 2:
            return []
    
        # Create array
        n = x + 1
        a = [True] * n
    
        # Sieve population
        for i in range(2, int(n ** 0.5) + 1):      # It's enough to look at the candidates 
            if a[i]:                               # up to the square root of the last number.
                for k in range(i * i, x + 1, i):
                    a[k] = False
    
        return [p for p in range(2, n) if a[p]]
    • # We can use Sieve of Eratosthenes for fast search of prime numbers
    • # https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
    • def primemaker(x):
    • # Edge cases
    • if x < 2:
    • return []
    • # Sieve initials
    • a = [True] * (x + 1)
    • a[0] = a[1] = False
    • primes = []
    • # Create array
    • n = x + 1
    • a = [True] * n
    • # Sieve population
    • for (i, isprime) in enumerate(a):
    • if isprime:
    • primes.append(i)
    • for n in range(i * i, x + 1, i):
    • a[n] = False
    • return primes
    • for i in range(2, int(n ** 0.5) + 1): # It's enough to look at the candidates
    • if a[i]: # up to the square root of the last number.
    • for k in range(i * i, x + 1, i):
    • a[k] = False
    • return [p for p in range(2, n) if a[p]]