Loading...
Loading...
Loading...
A catalogue needs a prime-numbered code for each item. Print how many prime numbers there are from 1 to N.
Example
Input
10
Output
4
The primes are 2, 3, 5 and 7.
Try the problem first. Open one hint at a time.
Testing every number separately is too slow. Mark the multiples of each prime instead.
Start crossing out at p * p and stop the outer loop at the square root of N.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor