FACVSPOW - Factorial vs Power 数学方法 + 二分
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 数学方法 + 二分的更多相关文章
- #8 Python数学方法
前言 前几节了解了Python的不同数据类型,有小伙伴会问,不同的数据类型之间是否可以相互转换?肯定是可以的,本篇博文主要记录数字类型的转换,其他类型的相互转换会在下几节记录,Here we go! ...
- zznu 1255 数字统计(数位DP, 数学方法)
最近在学数位DP, 感觉还是满有收获的! 做了几个题之后想起来自己OJ上曾经做的一道题,以前是用数学方法写的,现在改用数位DP来写了一遍. 题目: 1255: 数字统计 时间限制: 1 Sec 内存 ...
- js数组及常用数学方法
数组方法 清空数组 1: arr.length=0; 2: arr=[]; arr.push() //往数组最后一个添加元素,会待会一个返回值,就是新的数组长度arr.uns ...
- d3 数学方法(伪随机数生成器 )
一.正态(高斯)分布(normal (Gaussian) distribution)的随机数 /* var nomarlRandmo = d3.random.normal(); console.log ...
- 【BZOJ2876】【NOI2012】骑行川藏(数学,二分答案)
[BZOJ2876][NOI2012]骑行川藏(数学,二分答案) 题面 BZOJ 题解 我们有一个很有趣的思路. 首先我们给每条边随意的赋一个初值. 当然了,这个初值不会比这条边的风速小. 那么,我们 ...
- 123457123456#0#-----com.twoapp.mathGame13--前拼后广--13种数学方法jiemei
com.twoapp.mathGame13--前拼后广--13种数学方法jiemei
- three.js 数学方法之Box3
从今天开始郭先生就会说一下three.js 的一些数学方法了,像Box3.Plane.Vector3.Matrix3.Matrix4当然还有欧拉角和四元数.今天说一说three.js的Box3方法(B ...
- three.js 数学方法之Plane
今天郭先生就来继续说一说three.js数学方法中的plane(平面).在三维空间中无限延伸的二维平面,平面方程用单位长度的法向量和常数表示.构造器为Plane( normal : Vector3, ...
- POJ-2109 Power of Cryptography(数学或二分+高精度)
题目链接: https://vjudge.net/problem/POJ-2109 题目大意: 有指数函数 k^n = p , 其中k.n.p均为整数且 1<=k<=10^9 , 1< ...
随机推荐
- 【bzoj1433】[ZJOI2009]假期的宿舍
按要求连边,跑匈牙利 #include<algorithm> #include<iostream> #include<cstdlib> #include<cs ...
- JavaScript 实现块级作用域
(function(){ 块级作用域: })();
- 线程安全 对StringBuilder抛出ArrayIndexOutOfBoundsException的探究
对StringBuilder抛出ArrayIndexOutOfBoundsException的探究 - CSDN博客 https://blog.csdn.net/liu_005/article/det ...
- 学习html5 中的canvas(一)
1.canvas画直线 <!doctype html> <html> <head> <meta charset="UTF-8"> & ...
- 探讨Ajax中有关readyState(状态值)和status(状态码)的问题
先看下面一段代码,然后给大家详细介绍,Ajax中有关readyState(状态值)和status(状态码)的问题,具体内容如下所示: var getXmlHttpRequest = function ...
- select下拉带图片-模拟下拉
<style> /*下拉列表*/ ul,dl,ol,li {list-style: none;} .dropdown { float: right; position: relative; ...
- I.MX6 Android /data 目录内容
/**************************************************************************** * I.MX6 Android /data ...
- WC2017游记
Day0 到杭州之后出了点锅换了辆车,等了好久才开= =到宿舍发现路由器就在房门口,稳啊,过了一会儿就连不上了= =而且只有门口那个连不上,可以连上楼下的= =之后干了啥也忘了…… Day1 上午直接 ...
- CF838D Airplane Arrangement
题目描述:https://www.luogu.org/problemnew/show/CF838D(有翻译) (为什么博客园把我刚写的给吞了……orz) 这题当初看的十分懵逼,不过听了肖大佬的做法还是 ...
- MultiAutoCompleteTextView
Activity_mian.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...