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

有很多组询问,给个常数1<=a<=100w,求使得n! > a^n 的最小整数n

构造f(n)=n!,g(n)=a^n,a是常数,由高中知识就很容易知道f(n)趋近极限的速度最后会更快

不妨令h(n)=f(n)-g(n),则h(n)应当是递增的(吧?)

只要求h(n)=(n!-a^n) > 0的最小n

因此可知当a增加的时候,h(n)的零点应当也是增加的

所以可以枚举个a的值,不断增加n的值,只要n!>a^n,即log(n!)>nloga

即log1+log2+...+logn>nloga

左边的部分可以在枚举a的时候顺便求得

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n;
int ans[];
int main()
{
double s=;int t=;
for (int i=;i<=;i++)
{
while (s<=t*log(i)){t++;s+=log(t);}
ans[i]=t;
}
int T=read();
while (T--){printf("%d\n",ans[read()]);}
}

Spoj FACVSPOW

Spoj-FACVSPOW Factorial vs Power的更多相关文章

  1. FACVSPOW - Factorial vs Power 数学方法 + 二分

    http://www.spoj.com/problems/FACVSPOW/ 求解n! > a^n最小的整数n 对于有n!和a^n的东西,一般是取ln 然后就是求解 (ln(1) + ln(2) ...

  2. SPOJ #11 Factorial

    Counting trailing 0s of n! It is not very hard to figure out how to count it - simply count how many ...

  3. 【SPOJ】Power Modulo Inverted(拓展BSGS)

    [SPOJ]Power Modulo Inverted(拓展BSGS) 题面 洛谷 求最小的\(y\) 满足 \[k\equiv x^y(mod\ z)\] 题解 拓展\(BSGS\)模板题 #inc ...

  4. 「SPOJ 3105」Power Modulo Inverted

    「SPOJ 3105」Power Modulo Inverted 传送门 题目大意: 求关于 \(x\) 的方程 \[a^x \equiv b \;(\mathrm{mod}\; p) \] 的最小自 ...

  5. SPOJ:Divisors of factorial (hard) (唯一分解&分块优化)

    Factorial numbers are getting big very soon, you'll have to compute the number of divisors of such h ...

  6. SPOJ #752. Power it!

    By property of mod operations , we can simply use Divide and Conquer + Recursion to solve it. Refere ...

  7. MOOCULUS微积分-2: 数列与级数学习笔记 6. Power series

    此课程(MOOCULUS-2 "Sequences and Series")由Ohio State University于2014年在Coursera平台讲授. PDF格式教材下载 ...

  8. [BZOJ2616]SPOJ PERIODNI 树形dp+组合数+逆元

    2616: SPOJ PERIODNI Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 128  Solved: 48[Submit][Status][ ...

  9. 2016.5.16——leetcode:Rotate Array,Factorial Trailing Zeroe

    Rotate Array 本题目收获: 题目: Rotate an array of n elements to the right by k steps. For example, with n = ...

随机推荐

  1. 洛谷 P2935 [USACO09JAN]最好的地方Best Spot

    题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 ...

  2. MINST手写数字识别(二)—— 卷积神经网络(CNN)

    今天我们的主角是keras,其简洁性和易用性简直出乎David 9我的预期.大家都知道keras是在TensorFlow上又包装了一层,向简洁易用的深度学习又迈出了坚实的一步. 所以,今天就来带大家写 ...

  3. CSAPP lab1 datalab-handout

    这是一个关于机器级的整数.浮点数表示和位运算的实验.要求用给定的操作符.尽可能少的操作数去实现对应的函数功能. 完整的实验包:链接: https://pan.baidu.com/s/1xUBi3XDl ...

  4. 一个batch如何通过一个网络

    一个batch下所有的图片一起经过整个网络,不是说一张图片经过网络后再让下一张进入网络,这样一个batch一起通过网络计算速度比一张一张这样快

  5. 【转载】WPF DataGrid 性能加载大数据

    作者:过客非归 来源:CSDN 原文:https://blog.csdn.net/u010265681/article/details/76651725 WPF(Windows Presentatio ...

  6. vc生产垃圾清理

    @echo off echo 清除所有obj pch idb pdb ncb opt plg res sbr ilk suo文件,请稍等...... pause del /f /s /q .\*.ob ...

  7. Apache Commons Configuration的应用

    Apache Commons Configuration的应用 Commons Configuration是一个java应用程序的配置管理工具.可以从properties或者xml文件中加载软件的配置 ...

  8. 选择法数组排序参考(Java)

    package com.swift; public class Xuanze { public static void main(String[] args) { int[] arr= {28,2,3 ...

  9. substring substr slice 区别

    1. substring(start,end)  返回指定索引区间的字串,不改变原字符串 start 必需,开始位置的索引,一个非负的整数 end  可选,结束位置的索引(不包括其本身),如果未设置, ...

  10. [LUOGU] P2679 子串

    一开始用一个f数组转移,发现不太对,状态有重叠部分 f[i][j][k]表示考虑了s的前i位,匹配到t的第j位,用了k个子串,且s的第i位必选 g[i][j][k]表示考虑了s的前i位,匹配到t的第j ...