Sieve of Primes (Math)

Print how many primes are ≤ n, then the last (largest) one, as count largest. If there are none print 0 none.

Input: One integer 1 ≤ n ≤ 5000000.

Output: count largest.

Difficulty: Hard. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Trial division is too slow at the top end: use the Sieve of Eratosthenes.

More Math practice