PIXELBANKv8.2.1
Menu

Prime Finder

Problem Statement

Find all prime numbers up to a given limit.

Background

A prime number is only divisible by 1 and itself. The Sieve of Eratosthenes is an efficient algorithm:

  1. Create a list of numbers from 2 to n
  2. Start with the first prime (2)
  3. Remove all multiples of that prime
  4. Move to the next unmarked number
  5. Repeat until done

Your Task

Write a function find_primes(n) that returns all prime numbers up to n.

Output Format

Return a list of prime numbers in ascending order.

Example:

Input:
n = 20
Output:
[2, 3, 5, 7, 11, 13, 17, 19]
Reasoning:

Filter out composites: 4,6,8,9,10,12,14,15,16,18,20 leaving primes

Constraints:

  • n >= 2
  • Use an efficient approach for larger n
Editor

Test Results

0/0
Run code to see test results.