FACVSPOW - Factorial vs Power


Consider two integer sequences f(n) = n! and g(n) = an, where n is a positive integer. For any integer a > 1 the second sequence is greater than the first for a finite number of values. But starting from some integer k, f(n) is greater than g(n) for all n >= k. You are to find the least positive value of n for which f(n) > g(n), for a given positive integer a > 1.

Input

The first line of the input contains number t – the amount of tests. Then t test descriptions follow. Each test consist of a single number a.

Constraints

1 <= t <= 100000
2 <= a <= 106

Output

For each test print the least positive value of n for which f(n) > g(n).

Example

Input:
3
2
3
4

Output:
4
7
9

hide comments
sarelfeniel: 2014-04-30 07:21:01

Good problem. No idea how the fastest people are doing it. Must be secrets of mathematics I do not know.

Some good test cases from the forum that helped me

--edit(francky)--> Please do not add test cases, those in description should be enough.

@Francky I guess... honestly it takes < 3 seconds to go to the forum to find additional cases.

Last edit: 2014-05-04 10:11:40
Hasil Sharma: 2013-07-01 09:42:20

newton raphson or something else to be used by any chance ?

raunakrocks: 2013-04-11 08:10:52

esy math...no its programming..AC!!

Inspiron: 2013-02-17 07:43:29

nice prob....

devu: 2012-07-20 14:35:23

Sab Funde Baji Hai .. Think Programming ,not mathematics ,mathematics part is simple....

sandeep pandey: 2011-03-10 13:51:08

avoid stirling appx.(due to precision issue).
think mathematics:-))

bashrc is back: 2011-02-01 07:51:45

I am getting TLE.....Am i missing something?

jacob: 2010-11-03 11:45:04

can anyone with an AC give me some test cases for very large numbers ~10^5 or ~10^6
i am getting a wrong answer using stirling approximation

Curiosa: 2010-08-29 09:11:52

dont calculate n! and a^n. just use some mathematics

:(){ :|: & };:: 2010-06-25 00:17:59


It is possible to get an Accepted verdict by using Stirling approximation :)

Last edit: 2010-06-25 00:19:42

Added by:Spooky
Date:2009-11-01
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Advancement Autumn 2009, http://sevolymp.uuuq.com/