ORIGINAL CODING QUESTION
Prime-numbered tickets
Count prime integers in the inclusive range 0..x.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
One nonnegative integer x.
Constraints
0 ≤ x ≤ 100000.
Example 1
Input
10
Output
4
The primes are 2,3,5,7.
Example 2
Input
1
Output
0
No primes occur.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Zero and one are not prime.
Hint 2
A prime marks its larger multiples as composite.
Hint 3
Start crossing out multiples at p².
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →