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. 在Ubuntu16.04安装YouCompleteMe

    作为从事了4年多嵌入式Linux工作的软件工程师,最近决定完全在ubuntu上工作,使用vim进行代码的阅读和编辑,然后尝试去安装vim相关的各种插件.从来没用过代码补全的我,在网上找到了插件omni ...

  2. url编码和解码平台

    http://meyerweb.com/eric/tools/dencoder/

  3. ES6新增rest的用法

    arguments类似Array但是并不是Array 而rest就是一个Array 用rest替代atguments eg:给数组排序 //arguments变量的写法: function sortF ...

  4. w3 parse a url

     最新链接:https://www.w3.org/TR/html53/ 2.6 URLs — HTML5 li, dd li { margin: 1em 0; } dt, dfn { font-wei ...

  5. helm istio k8s docker

    helm https://hub.helm.sh/ k8s https://www.kubernetes.org.cn/k8s istio 微服务 https://istio.io/

  6. 关于Java IO流学习总结

    一.IO流的三种分类方式 1.按流的方向分为:输入流和输出流 2.按流的数据单位不同分为:字节流和字符流 3.按流的功能不同分为:节点流和处理流     二.IO流的四大抽象类: 字符流:Reader ...

  7. 开启和连接mysql服务器(win10为例)

    1.windows图标右键,选择“计算机管理”: 2.展开左边的“ 服务和应用程序” 选项,点击“服务",找到 MySQL 服务器,点击左侧的 "启动",即可完成 MyS ...

  8. react 列表渲染

    https://reactjs.org/docs/lists-and-keys.html#keys 以下代码运行会报错:Warning: Each child in an array or itera ...

  9. Juqyer:$.ajax()方法详解

    Jquery中的ajax方法参数总是记不住,这里记录一下. 最常用的属性是:url.data 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为S ...

  10. 第一章 pyhton基础

    一 .pyhton2与python3的区别 在pyhton2中,其中编码默认使用的是ascii编码,输出格式为print"xxx",输入为raw_input(“请输入”),在整型中 ...