Ad

more speed to the god of speed

Code
Diff
  • def number_of_primes(n):
        if n == 0:
            return []
    
        p, i = [2], 3
        while len(p) < n:
            is_prime = True
            for v in p:
                if i % v == 0:
                    is_prime = False
                    break
                if v * v > i:
                    break
            if is_prime:
                p.append(i)
            i += 2
    
        return p
    • def number_of_primes(n):
    • p, i = [], 2
    • if n == 0:
    • return []
    • p, i = [2], 3
    • while len(p) < n:
    • if all(i % d for d in range(2, int(i**0.5) + 1)):
    • is_prime = True
    • for v in p:
    • if i % v == 0:
    • is_prime = False
    • break
    • if v * v > i:
    • break
    • if is_prime:
    • p.append(i)
    • i += 1
    • i += 2
    • return p