MANGOES - Real Mangoes for Ranjith

no tags 

Ranjith is very fond of mangoes. One fine sunny day, he goes to market to get some mangoes. In the market place, he finds N boxes (indexed from 1 to N), filled with mangoes kept infront of him. Each box indexed i is denoted by bi and contains exactly i mangoes. The number of mangoes in bi is denoted by mi and m_i = i. Let ti denotes the type of mangoes in box bi (ti is either "real" or "fake"). He can choose any box bi (i <= N-2), but he doesn't know if the box contains "real" mangoes or "fake" mangoes i.e. type of box bi.

The type of mangoes in bi depends on the number of mangoes in boxes bi, bi+1, bi+2 i.e. {mi, mi+1, mi+2}. Mangoes in box bi are "real" if for each pair of numbers taken from set {mi, mi+1, mi+2}, Greatest common divisor(GCD) equals 1. Otherwise, "fake". Note that ti is not defined for i = N-1 and i = N and assumed to be "fake". 

Given N, Ranjith wants to know the total number of "real" mangoes he will get from all boxes. As Ranjith cannot count beyond N, output the result modulo N.

Input

Test File starts with number of test cases - T;

T lines follows, each containing N, number of boxes.

Output

Output T lines Number of "real" mangoes Ranjith gets (modulo N) in each one of the T cases.

Constraints

2 < N <= 10^8
T <= 10000

Example

Input:
2
9
5

Output:
7
4

hide comments
vishal chaudhary: 2013-05-18 14:37:21

got 2 WA due to a silly mistake...xD

avinash: 2013-04-16 15:21:29

why am i getting NZEC :( main() returns 0 from my code but still getting NZEC..

Ouditchya Sinha: 2013-03-31 15:05:03

@ Kevin Sebastian, it can be done in O(1), just solve for small values of n to arrive at a formula. :)

Kevin Sebastian: 2013-03-30 10:30:44

could it be done in o(n)?

Ouditchya Sinha: 2013-03-16 09:16:26

too easy... :D

(Tjandra Satria Gunawan)(曾毅昆): 2013-03-15 05:57:23

@Kevin Sebastian: Ok, no problem :-)

Kevin Sebastian: 2013-03-15 05:31:02

@Tjandra please remember that there are novice coders too here

Kevin Sebastian: 2013-03-15 04:46:35

getting TLE

[Lakshman]: 2013-03-13 21:34:30

@Eduardo Nunes
GOT AC after changing the logic...Thanks a

Last edit: 2013-03-14 00:13:02
Eduardo Nunes: 2013-03-13 20:41:20

@radhey,
for n=5, answer is 4 because the total real mangoes are 4 (modulo 5), i.e., the sum of the mi in each of the bi that corresponds to the description {1, 3} which is 4 (and 4 = 4 modulo 5)

@Lakshman, try to see what the problem asks in fact... ;-)

@Tjandra, @Neo, @all-that-says-it-should-be-in-tutorial,
it COULD be in tutorial, but we need some thinking before realizing how simple the question is, indeed...

Last edit: 2013-03-14 22:05:58

Added by:Gopal Rander
Date:2013-02-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Bytecode '13