http://www.spoj.com/problems/FACVSPOW/

求解n! > a^n最小的整数n

对于有n!和a^n的东西,一般是取ln

然后就是求解

(ln(1) + ln(2) + .... + ln(n)) / n > ln(a)的最小整数n

发现左边的函数单调,所以可以预处理出来,右边最大值是ln(1e6)

所以预处理5e6个。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 5e6 + ;
double f[maxn];
void init() {
for (int i = ; i <= maxn - ; ++i) {
f[i] = (f[i - ] * (i - ) + log(i * 1.0)) / (i * 1.0);
}
// for (int i = 1; i <= 100; ++i) {
// cout << f[i] << endl;
// }
}
int a;
double up;
const double eps = 1e-;
bool bigger(double a, double b) {
return a - b > eps;
}
void work() {
scanf("%d", &a);
up = log(a * 1.0);
int be = , en = maxn - ;
while (be <= en) {
int mid = (be + en) >> ;
if (bigger(f[mid], up)) {
en = mid - ;
} else be = mid + ;
}
printf("%d\n", be);
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
init();
int t;
scanf("%d", &t);
while (t--) work();
return ;
}

据说

ln(n!) ≈ (n * ln(n)) - n + (1 / 2 * ln(2 * PI * n));

FACVSPOW - Factorial vs Power 数学方法 + 二分的更多相关文章

  1. #8 Python数学方法

    前言 前几节了解了Python的不同数据类型,有小伙伴会问,不同的数据类型之间是否可以相互转换?肯定是可以的,本篇博文主要记录数字类型的转换,其他类型的相互转换会在下几节记录,Here we go! ...

  2. zznu 1255 数字统计(数位DP, 数学方法)

    最近在学数位DP, 感觉还是满有收获的! 做了几个题之后想起来自己OJ上曾经做的一道题,以前是用数学方法写的,现在改用数位DP来写了一遍. 题目: 1255: 数字统计 时间限制: 1 Sec  内存 ...

  3. js数组及常用数学方法

    数组方法 清空数组   1: arr.length=0;   2: arr=[]; arr.push()          //往数组最后一个添加元素,会待会一个返回值,就是新的数组长度arr.uns ...

  4. d3 数学方法(伪随机数生成器 )

    一.正态(高斯)分布(normal (Gaussian) distribution)的随机数 /* var nomarlRandmo = d3.random.normal(); console.log ...

  5. 【BZOJ2876】【NOI2012】骑行川藏(数学,二分答案)

    [BZOJ2876][NOI2012]骑行川藏(数学,二分答案) 题面 BZOJ 题解 我们有一个很有趣的思路. 首先我们给每条边随意的赋一个初值. 当然了,这个初值不会比这条边的风速小. 那么,我们 ...

  6. 123457123456#0#-----com.twoapp.mathGame13--前拼后广--13种数学方法jiemei

    com.twoapp.mathGame13--前拼后广--13种数学方法jiemei

  7. three.js 数学方法之Box3

    从今天开始郭先生就会说一下three.js 的一些数学方法了,像Box3.Plane.Vector3.Matrix3.Matrix4当然还有欧拉角和四元数.今天说一说three.js的Box3方法(B ...

  8. three.js 数学方法之Plane

    今天郭先生就来继续说一说three.js数学方法中的plane(平面).在三维空间中无限延伸的二维平面,平面方程用单位长度的法向量和常数表示.构造器为Plane( normal : Vector3, ...

  9. POJ-2109 Power of Cryptography(数学或二分+高精度)

    题目链接: https://vjudge.net/problem/POJ-2109 题目大意: 有指数函数 k^n = p , 其中k.n.p均为整数且 1<=k<=10^9 , 1< ...

随机推荐

  1. queue_action

    http://www.learn4master.com/programming-language/python/python-queue-for-multithreading

  2. SpringMVC 学习笔记(四) 处理模型数据

    Spring MVC 提供了下面几种途径输出模型数据: – ModelAndView: 处理方法返回值类型为 ModelAndView时, 方法体就可以通过该对象加入模型数据 – Map及Model: ...

  3. 解析SQL中的包含的列和表

    using System; using System.IO; using System.Collections.Generic; namespace SQLProcess { class Progra ...

  4. Java面试手写代码题

    1.栈实现 2.Iterator实现 3.单例 4.多线和控制(暂停,恢复,停止) 5.生产者消费者

  5. Educational Codeforces Round 10 D. Nested Segments

    D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. FZU1686 神龙的难题 —— Dancing Links 可重复覆盖

    题目链接:https://vjudge.net/problem/FZU-1686 Problem 1686 神龙的难题 Accept: 812    Submit: 2394 Time Limit: ...

  7. Spring Boot2.0+Redis+Ehcache实现二级缓存

    EHCache 本地缓存 Redis 分布式缓存(可以共享) 一级 Redis 二级Ehcache    当redis挂了 有备胎 反之: 先走本地,本地没有再走网络  尽量少走Redis  效率会高 ...

  8. html5--3.2 input元素(2)

    html5--3.2 input元素(2) 学习要点 input元素及其属性 input元素 用来设置表单中的内容项,比如输入内容的文本框,按钮等 不仅可以布置在表单中,也可以在表单之外的元素使用 i ...

  9. html5--6-23 CSS3中的文字与字体

    html5--6-23 CSS3中的文字与字体 text-overflow 设置是否使用一个省略标记(...)标示对象内文本的溢出 clip: 默认值当对象内文本溢出时不显示省略标记(...),而是将 ...

  10. html5--6-19 CSS3中的文字与字体

    html5--6-19 CSS3中的文字与字体 学习要点 掌握文字与字体的设置 颜色值查询方法: 百度查询,很多网站有提供 下载相关手册等需要时查表 运用绘图工具中的拾色器 CSS中常用的字体属性设置 ...