Spoj-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
有很多组询问,给个常数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的更多相关文章
- FACVSPOW - Factorial vs Power 数学方法 + 二分
http://www.spoj.com/problems/FACVSPOW/ 求解n! > a^n最小的整数n 对于有n!和a^n的东西,一般是取ln 然后就是求解 (ln(1) + ln(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 ...
- 【SPOJ】Power Modulo Inverted(拓展BSGS)
[SPOJ]Power Modulo Inverted(拓展BSGS) 题面 洛谷 求最小的\(y\) 满足 \[k\equiv x^y(mod\ z)\] 题解 拓展\(BSGS\)模板题 #inc ...
- 「SPOJ 3105」Power Modulo Inverted
「SPOJ 3105」Power Modulo Inverted 传送门 题目大意: 求关于 \(x\) 的方程 \[a^x \equiv b \;(\mathrm{mod}\; p) \] 的最小自 ...
- SPOJ:Divisors of factorial (hard) (唯一分解&分块优化)
Factorial numbers are getting big very soon, you'll have to compute the number of divisors of such h ...
- SPOJ #752. Power it!
By property of mod operations , we can simply use Divide and Conquer + Recursion to solve it. Refere ...
- MOOCULUS微积分-2: 数列与级数学习笔记 6. Power series
此课程(MOOCULUS-2 "Sequences and Series")由Ohio State University于2014年在Coursera平台讲授. PDF格式教材下载 ...
- [BZOJ2616]SPOJ PERIODNI 树形dp+组合数+逆元
2616: SPOJ PERIODNI Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 128 Solved: 48[Submit][Status][ ...
- 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 = ...
随机推荐
- C#遍历文件夹下全部文件
public static List<string> GetFile(string path, List<string> FileList, string RelativePa ...
- License开源许可协议
开源许可协议 License是软件的授权许可,表述了你获得代码后拥有的权利,可以对别人的作品进行何种操作,何种操作又是被禁止的. 开源许可证种类 Open Source Initiative http ...
- Spring中的事务传播行为与隔离级别
事务传播行为 事务传播行为(为了解决业务层方法之间互相调用的事务问题): 当事务方法被另一个事务方法调用时,必须指定事务应该如何传播.例如:方法可能继续在现有事务中运行,也可能开启一个新事务,并在自己 ...
- python基础一 day14 生成器函数进阶
def generator(): print(123) content = yield 1 print('=======',content) print(456) arg = yield 2 '''' ...
- faster rcnn需要理解的地方
http://blog.csdn.net/terrenceyuu/article/details/76228317 https://www.cnblogs.com/houkai/p/6824455.h ...
- common-fileupload上传文件
文件上传在web应用中非常普遍,要在jsp环境中实现文件上传功能是非常容易的,因为网上有许多用java开发的文件上传组件,本文以commons-fileupload组件为例,为jsp应用添加文件上传功 ...
- Bootstrap历练实例:垂直的按钮组
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- ios之UITextfield
//初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 13 ...
- python基础知识13-迭代器与生成器,导入模块
异常处理作业讲解 file = open('/home/pyvip/aaa.txt','w+') try: my_dict = {'name':'adb'} file.write(my_dict['a ...
- 【实验吧】因缺思汀的绕过&&拐弯抹角&&Forms&&天网管理系统
<?php error_reporting(); if (!isset($_POST['uname']) || !isset($_POST['pwd'])) { echo '<form a ...