传送门

题意:

给出\(x,x\leq 12\),求最大的\(n\),满足\(n!\leq 2^{2^x}\)。

思路:

通过斯特林公式:

\[n!\approx \sqrt{2\pi n}\cdot (\frac{n}{e})^n
\]

我们一般可以认为这两个相等= =

将阶乘转化为一个比较好求的式子,然后二分判断一下即可。

/*
* Author: heyuhhh
* Created Time: 2019/12/10 21:14:22
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << '\n'; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
#define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5; int n; bool chk(double x) {
return 0.5 * log(2 * 3.1415926 * x) + x * log(x) - x <= pow(2, n) * log(2);
} void run(){
if(n == 0) return;
n = (n - 1940) / 10 * 10 / 10;
double l = 1, r = 1000000000000000, mid;
for(int i = 0; i < 1000; i++) {
mid = (l + r) / 2;
if(chk(mid)) l = mid;
else r = mid;
}
cout << (ll)l << '\n';
} int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
while(cin >> n) run();
return 0;
}

【poj2661】Factstone Benchmark(斯特林公式)的更多相关文章

  1. poj2661 Factstone Benchmark(大数不等式同取对数)

    这道题列出不等式后明显是会溢出的大数,但是没有必要写高精度,直接两边取对数(这是很简明实用的处理技巧)得: log2(n!)=log2(n)+log2(n-1)+...+log2(1)<=log ...

  2. uva 10916 Factstone Benchmark(对数函数的活用)

    Factstone Benchmark Amtel has announced that it will release a 128-bit computer chip by 2010, a 256- ...

  3. HDU 1141 Factstone Benchmark (数学 )

    题目链接 Problem Description Amtel has announced that it will release a 128-bit computer chip by 2010, a ...

  4. Factstone Benchmark

    [问题描述] Amtel已经宣布,到2010年,它将发行128位计算机芯片:到2020年,它将发行256位计算机:等等,Amtel坚持每持续十年将其字大小翻一番的战略.(Amtel于2000年发行了6 ...

  5. poj 2661 Factstone Benchmark (Stirling数)

    //题意是对于给定的x,求满足n! <= 2^(2^x)的最大的n//两边同取以二为底的对数,可得: lg2(n!) <= 2^x 1.   log2(n!) = log2(1) + lo ...

  6. sicily 1119 Factstone Benchmark

    题意:求满足n! < 2^k,n的最大值! 解题:指数比较转换成对数比较,达到降幂! 其中: log (n!) = log(n)+log(n-1)+...+log(1); log(2^k) = ...

  7. poj 2661 Factstone Benchmark

    /** 大意: 求m!用2进制表示有多少位 m! = 2^n 两边同时取对数 log2(m!) = n 即 log2(1) + log2(2)+log2(3)+log2(4)...+log2(m) = ...

  8. Factstone Benchmark(数学)

    http://poj.org/problem?id=2661 题意:Amtel在1960年发行了4位计算机,并实行每十年位数翻一番的策略,将最大整数n作为改变的等级,其中n!表示计算机的无符号整数(n ...

  9. POJ-2661Factstone Benchmark

    Factstone Benchmark Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5577   Accepted: 25 ...

随机推荐

  1. Snack3 之 Jsonpath使用

    Snack3 之 Jsonpath使用 一. Snack3 和 JSONPath 介绍 Snack3 是一个支持JSONPath的JSON框架.JSONPath是一个很强大的功能,也可以在Java框架 ...

  2. VM虚拟机与本地网络互通配置

    一.设置虚拟机网络 1. 查看虚拟机网络NAT设置(VMnet8) 2. 设置虚拟机网络适配器为NAT模式 三.设置本机VMnet8网络属性 三.设置Linux网络属性 1. 查看 ip addr 2 ...

  3. net.sf.json将string转为map

    背景 改一个以前的项目,项目里只有这个包,虽然我想用gson或者fastjson,然而并不想引入新的jar.于是使用这个,特此记录,感觉贼不好用. 实现代码 entity.getData()的值:{a ...

  4. WebShell代码分析溯源(十)

    WebShell代码分析溯源(十) 一.一句话变形马样本 <?php $e = $_REQUEST['e'];register_shutdown_function($e, $_REQUEST[' ...

  5. Nlog配置

    初次使用nlog,里里外外找了好久,终于搞会了. 使用nlog建日志输出到txt文件.数据库.邮件 nlog配置,如图 码云dome

  6. Vue学习笔记Day2

    1.mustache语法 如何将data中的文本数据插入到HTML中? 通过使用mustache语法(也就是双大括号),将data中的变量名插入到HTML元素中,显示在页面上. 如下图:并且数据是响应 ...

  7. elasticsearch对无意义的词进行屏蔽——停用词

    介绍 在使用elasticsearch进行搜索业务的时候,发现一篇和搜索关键字完全不匹配的文章排在最前面.打开它发现原来是这篇文章含有非常多的"的"这个无意义的词.而我的搜索关键字 ...

  8. arcgis api 4.x for js 结合 Echarts4 实现统计图(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 4.x for js:esri 官网 api,里面详细的介绍 arcgis api 4.x 各个类 ...

  9. iOS字符串处理_替换(去掉空格换行)、截取

    以下代码主要实现了:1.截取"@@"前的字符串:  2.去掉字符串中的"##":  3.去掉字符串中的空格和换行. 希望相互学习相互指正. -----ViewC ...

  10. enable SSL on weblogic

    To provision (install) a certificate on the server On the Start menu, click Run, and in the Open box ...