FACTMULN - Product of factorials (easy)

no tags 

For n positive integer, let F(n) = 1! × 2! × 3! × 4! × ... × n!, product of factorial(i) for i in [1..n].

Let G(n) = {i in [1..n], such that n divides F(i)}.

It is obvious that n belongs to G(n) that makes it a non empty set.

Input

The first line of input contains an integer T, the number of test cases.
On each of the next T lines, your are given an integer n.

Output

For each test case, you have to print min(G(n)).

Example

Input:
3
4
5
6
Output:
3
5
3

Explanation

For test case #1:
F(1) = 1! = 1 , not divisible by 4
F(2) = 1! × 2! = 2 , not divisible by 4
F(3) = 1! × 2! × 3! = 12 , divisible by 4
F(4) = 1! × 2! × 3! × 4! = 288 , divisible by 4
So G(4) = {3, 4}.

Constraints

0 < T < 10^4
0 < n < 10^9

A little kB of Python code can get AC in half the time limit. (Edit 2017-02-11, after the compiler changes.)
Input is not randomly chosen ;-) Have fun.


hide comments
Vipul Srivastava: 2016-12-18 14:50:32

Lovely question..!!

aishik_pyne: 2015-09-19 10:49:45

soln id:15160697
@Francky it's not a navie solution but it still gives TLE
can you check and tell me if i have to improve on the code?

=(Francky)=> You should use a sieving method, instead of a next_P function, way too slow.

Last edit: 2015-09-21 14:50:11
varun bumb: 2015-07-25 23:13:59

Nice problem!

Sayak Haldar: 2015-07-17 00:11:02

Last edit: 2015-07-17 00:31:14
:.Mohib.:: 2015-05-26 16:46:47

Finally done...!! Awsm problem....!!
Thnx for the problem Francky sir... :)

Last edit: 2015-06-22 11:10:49
Soma: 2015-01-15 09:03:12

@Francky can you please check where my code is giving WA.. my submission ID=13431072
--Francky--> You could check, for example, when you are given a power of 2.


@francky thank you. my solution got accepted.

Last edit: 2015-01-21 15:47:03
Mayank Poply: 2014-12-28 21:06:09

@Francky - Can u give me a test case for which my code fails?I am getting WA Submission ID - 13293486
--(francky)--> For an important amount of cases, your program output 13, and it's not the answer. You can solve some small cases, it's true.

Last edit: 2014-12-28 21:13:10
Francky: 2014-11-22 10:28:27

@Shanmukh : your assert is wrong, you have always 0 < n < 10^9 in the input file.

Last edit: 2014-11-22 10:29:55
:(: 2014-11-22 06:13:48

Range of n is more than 10^9 ... Make your code for entire int range. Got 9 WA's due to unclear range :( . Finally AC :D

Last edit: 2014-11-22 08:53:55
Sandeep Singh: 2014-08-28 23:17:19

Finally solve it , there are some corner(difficult) cases :)

Last edit: 2014-08-28 23:18:37

Added by:Francky
Date:2014-03-01
Time limit:1.659s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own Problem