Back to problems

Implement scalable prime generator

Algorithm · Pinterest · Medium

Implement solution(n, return_last_only=False). By default, the function should return the first n prime numbers in increasing order. If return_last_only is set to True, skip materializing the entire prefix and instead return a single-item list containing only the n-th prime. When n is 0, return an empty list regardless of return_last_only. Do not test each candidate integer independently using trial division. Use a sieve-based method and choose a safe upper estimate for the…

Checking your access…