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 = ...
随机推荐
- watchguard 软件工程师内部招聘!
作为watchguard正式员工,现发布公司最近的招聘信息,待遇优厚,请符合条件的朋友和我联系并将简历发给我,我会尽早联系公司人力部门. 我的邮件:daibao91888@163.com 博客:htt ...
- python hdfs初体验
新建目录 chr 新建文件hdfstest1.txt并写入内容 复制hdfstest1.txt的内容到hdfstest2.txt
- urllib2功能说明
1.urlopen(url, data, timeout) 第一个参数url即为URL,第二个参数data是访问URL时要传送的数据,第三个timeout是设置超时时间. 第二三个参数是可以不传送的, ...
- WINDOWS-基础:_T
_T("")是一个宏,定义于tchar.h下. #define __T(x) L ## x #define _T(x) __T(x) 作用 他的作用是让你的程序支持Unicode编 ...
- MySQL数据库安全配置
文章来源:http://www.xfocus.net MySQL数据库安全配置 1.前言 MySQL 是完全网络化的跨平台关系型数据库系统,同时是具有客户机/服务器体系结构的分布式数据库管理系统.它具 ...
- java在线聊天项目0.2版本 制作客户端窗体,使用swing(用户界面开发工具包)和awt(抽象窗口工具包) BorderLayout布局与GridLayout布局不同之处 JPanel设置大小
代码如下: package com.swift; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JBu ...
- String中indexof函数的用法
int indexOf(int ch) 返回指定字符在此字符串中第一次出现处的索引. int indexOf(int ch, int fromIndex) 从指定的索引开始搜索,返回在此字符串中第一次 ...
- laravel 设计思想简单了解
服务容器 laravel框架中 服务容器是整个系统功能调度配置的核心,在系统运行过程中动态的为系统提供需要的服务 从而实现了解耦 控制反转(IOC) 控制反转是一种设计模式 主要解决了系统组件之间的相 ...
- (转)自定义UITabBar
push页面时,可调用hidesBottomBarWhenPushed进行隐藏. 第一步,我们需要一些图片: 各个选项的图标和tabbar的背景图片,最后还要一个透明的1x1像素的图片. 第二步,新建 ...
- 使用Lucene的api将索引创建到索引库中
import org.apache.commons.io.FileUtils; import org.apache.lucene.document.Document; import org.apach ...