This page is still under construction.

Parts of this page are still being built. What you see may change.

YAPTCHA

Time limit1sMemory limit128 MB

Summary
For each query n, compute the sum of floor(((3k+6)!+1)/(3k+7) - floor((3k+6)!/(3k+7))) over k from 1 to n. The sum equals the count of primes among 3k+7 for k=1..n, so precompute primes up to 3n+7 and prefix counts.
Level

Hard8 of 10

Topics
Number theory, Math, Prefix sum, Brute force
Solved
No attempts yet

Problem

Every time Seonyeong solves a problem, she posts the solution method to her Practice Log. The site became so popular that a million people visit it every day.

Seonyeong dislikes people who copy only the source code and submit it to an online judge without reading the explanation. To stop this, she decided to add a Yet-Another-Public-Turing-test-to-tell-Computers-and-Humans-Apart (YAPTCHA) to her homepage.

This YAPTCHA is so hard that even students with a PhD or professors cannot solve it easily. Sanggeun, who wants to read the solutions, wants to write a program that solves the test automatically.

When you visit the homepage, you are given a natural number nn together with the following expression. If you compute its value SnS_n and enter it, you can view the solution. Given nn, write a program that computes SnS_n.

Sn=∑k=1n⌊(3k+6)!+13k+7−⌊(3k+6)!3k+7⌋⌋S_n = \sum_{k=1}^{n} \left\lfloor \frac{(3k+6)! + 1}{3k+7} - \left\lfloor \frac{(3k+6)!}{3k+7} \right\rfloor \right\rfloor

Here ⌊x⌋\lfloor x \rfloor denotes the greatest integer not greater than xx (the floor of xx).

Input

The first line contains the number of queries tt (t≤106t \le 10^6). Each of the following queries is given on its own line and consists of a single natural number nn (1≤n≤1061 \le n \le 10^6).

Output

For each query nn, print SnS_n on its own line.

Examples2

  1. Example 1

    Input
    13
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    100
    1000
    10000
    
    Expected output
    0
    1
    1
    2
    2
    2
    2
    3
    3
    4
    28
    207
    1609
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    0