Sphere Online Judge

SPOJ Problem Set (classical)

5161. Factorial vs Power

Problem code: FACVSPOW

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

Added by:Spooky
Date:2009-11-01
Time limit:2s
Source limit:50000B
Languages:All except: CLOJ F# GO PERL 6 TECS
Resource:Advancement Autumn 2009, http://sevolymp.uuuq.com/

hide comments
2010-08-29 11:11:52 თორნიკე
dont calculate n! and a^n. just use some mathematics
2010-08-05 13:23:56 Tarek Abdel-wareth
'a' cannot be more than 8
because at n=19:
19! IS < 9^19
and at n=20 9^20 is too large for a long long variable ?!!!!!!!!
2010-08-05 13:03:17 Tarek Abdel-wareth
that's IMPOSSIBLE in some cases
if a=10^6 (1000000)
it's impossible for n! to be greater than 1000000^n
So how is it possible ??????????????????
2010-07-14 14:34:44 J Sai Kiran Reddy
will O(n) get accepted...?
2010-06-25 02:17:59 .::: Debanjan :::.

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

Last edit: 2010-06-25 02:19:42
2010-06-08 20:38:55 Vamsi Kavala
cin & cout are pretty slow for this problem..i got several tle's using them..prefer scanf & printf :)
2009-11-26 17:21:56 Spooky
Maybe we can't. Although those are not billion digit numbers. Several slightly different approaches give the same results. And also I've checked some test cases with rather big numbers using Maple.
2009-11-26 16:11:21 amaroq
How can we be sure that we have enough precision if we can't work with billion digit numbers?
SPOJ System © 2010 Sphere Research Labs. All Rights Reserved.