📘
Prime Finder
MediumPython Algorithms
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:
- Create a list of numbers from 2 to n
- Start with the first prime (2)
- Remove all multiples of that prime
- Move to the next unmarked number
- 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
Python 3.13.1
Test Results
0/0Run code to see test results.