45. Count Primes Up To N
Challenge1000 ms256 MBSolved by 0%
Read an integer n and print how many prime numbers there are from
2 up to and including n.
If n is less than 2, the answer is 0.
Constraints - `1 ≤ n ≤ 1000000`
Input
A single line containing one integer n.
Output
Print one integer, how many primes are in the range 2 to n. Print 0 if n is below 2.
Input10
Output4
Notehas the primes 2, 3, 5 and 7
Input1
Output0
Noteis below the smallest prime, so the answer is zero
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.