YAPTCHA
Time limit1sMemory limit128 MB
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 together with the following expression. If you compute its value and enter it, you can view the solution. Given , write a program that computes .
Here denotes the greatest integer not greater than (the floor of ).
Input
The first line contains the number of queries (). Each of the following queries is given on its own line and consists of a single natural number ().
Output
For each query , print on its own line.