Under construction

Still being built. Things may change

Count many primes quickly with short code

Time limit5sMemory limit1024 MB

Summary
For each test case, count the primes less than or equal to N, where N can be up to 10^12 when there is only one test case.
Level

Medium7 of 10

Topics
Number theory, Math, Dynamic programming
Solved
No attempts yet

Input

The first line contains the number of test cases TT. (T≥1T \geq 1)

Each test case is given on its own line as a single positive integer NN.

At least one of the following holds.

  • T=1T = 1, N≤1012N \leq 10^{12}
  • T≤100T \leq 100, N≤109N \leq 10^9
  • T≤104T \leq 10^4, N≤106N \leq 10^6

Output

For each test case, print on its own line the number of primes less than or equal to NN.

Examples2

  1. Example 1

    Input
    4
    1
    10
    100
    1000000000
    
    Expected output
    0
    4
    25
    50847534
    
  2. Example 2

    Input
    1
    1000000000000
    
    Expected output
    37607912018