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 []
            
        # Sieve initials
        a = [True] * (x + 1)
        a[0] = a[1] = False
        primes = []
    
        # 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
    • # We can use Sieve of Eratosthenes for fast search of prime numbers
    • # https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
    • def primemaker(x):
    • if x<2: return []
    • primes = [2]
    • for possibleprimes in range(3,x+1, 2):
    • for n in range(2,int(possibleprimes**0.5)+1):
    • if possibleprimes % n == 0:
    • break
    • else:
    • primes.append(possibleprimes)
    • # Edge cases
    • if x < 2:
    • return []
    • # Sieve initials
    • a = [True] * (x + 1)
    • a[0] = a[1] = False
    • primes = []
    • # 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