SPOJ FACVSPOW 数论+二分
来源:互联网 发布:红蜘蛛破解软件 编辑:程序博客网 时间:2024/05/17 18:25
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 thang(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:3234Output:479
题意:输入a,找到满足n!>a^n 最小的n。
题解:
n*(n-1)*...*2*1>a*a*a...*a
ln(n)+ln(n-1)+...+ln(2)+ln(1)>ln(a)+ln(a)...+ln(a)
ln(a)<(ln(n)+ln(n-1)+...+ln(1))/n
预处理完二分查找
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;double pre[3000005];int main(){int n,t,i;double now=0;for(i=1;i<=3000000;i++){now+=log(i);pre[i]=now/i;}scanf("%d",&t);while(t--){scanf("%d",&n);int l=1,r=3000000;double d=log(n);while(l+1<r){int mid=l+r>>1;if(d<pre[mid])r=mid;else l=mid;}if(d<pre[l])printf("%d\n",l);else printf("%d\n",r);}return 0;}
- SPOJ FACVSPOW 数论+二分
- SPOJ FACVSPOW(数论+二分)
- SPOJ FACVSPOW
- SPOJ 5161 FACVSPOW
- SPOJ TBATTLE - Thor vs Frost Giants [数论+二分]
- SPOJ - DIV15(数论)
- SPOJ LCMSUM (数论)
- SPOJ GCDEX (数论)
- SPOJ LCMSUM (数论)
- Spoj数论专场解题报告
- 【SPOJ-ALICESIE】Alice Sieve【数论】
- SPOJ:Factorial Modulo(数论)
- SPOJ AGGRCOW 二分枚举
- SPOJ - PHT【二分+预处理】
- 11.1 考试 数论+数论+二分
- FZU 1988 二分+数论
- uva11428(数论+二分)
- SPOJ_TBATTLE:Thor_vs_Frost_Giants(数论+二分)
- 1013. Battle Over Cities (25)
- 有状态和无状态的session bean
- 设计模式之单件模式
- PIC精英年会资料下载
- <ol>标签,添加有序列表
- SPOJ FACVSPOW 数论+二分
- .NET中常用的知识点--数组、ArrayList和List的区别
- Java的ClassLoader分析与Jettty的WebAppClassLoader
- ContentResolver 内容访问者访问手机联系人
- 一个菜鸟的APP完整的血泪开发之路之一
- C语言中结构体的位域(bit-fields)
- Jetty的Servlt请求路由与ContextHandlerColleection的实现
- 爬虫系列(二)——网页解析Jsoup
- Composer笔记(一)补充:在linux下安装PHP Composer(完全安装)