【poj2661】Factstone Benchmark(斯特林公式)
题意:
给出\(x,x\leq 12\),求最大的\(n\),满足\(n!\leq 2^{2^x}\)。
思路:
通过斯特林公式:
\]
我们一般可以认为这两个相等= =
将阶乘转化为一个比较好求的式子,然后二分判断一下即可。
/*
* 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(斯特林公式)的更多相关文章
- poj2661 Factstone Benchmark(大数不等式同取对数)
这道题列出不等式后明显是会溢出的大数,但是没有必要写高精度,直接两边取对数(这是很简明实用的处理技巧)得: log2(n!)=log2(n)+log2(n-1)+...+log2(1)<=log ...
- uva 10916 Factstone Benchmark(对数函数的活用)
Factstone Benchmark Amtel has announced that it will release a 128-bit computer chip by 2010, a 256- ...
- HDU 1141 Factstone Benchmark (数学 )
题目链接 Problem Description Amtel has announced that it will release a 128-bit computer chip by 2010, a ...
- Factstone Benchmark
[问题描述] Amtel已经宣布,到2010年,它将发行128位计算机芯片:到2020年,它将发行256位计算机:等等,Amtel坚持每持续十年将其字大小翻一番的战略.(Amtel于2000年发行了6 ...
- poj 2661 Factstone Benchmark (Stirling数)
//题意是对于给定的x,求满足n! <= 2^(2^x)的最大的n//两边同取以二为底的对数,可得: lg2(n!) <= 2^x 1. log2(n!) = log2(1) + lo ...
- sicily 1119 Factstone Benchmark
题意:求满足n! < 2^k,n的最大值! 解题:指数比较转换成对数比较,达到降幂! 其中: log (n!) = log(n)+log(n-1)+...+log(1); log(2^k) = ...
- poj 2661 Factstone Benchmark
/** 大意: 求m!用2进制表示有多少位 m! = 2^n 两边同时取对数 log2(m!) = n 即 log2(1) + log2(2)+log2(3)+log2(4)...+log2(m) = ...
- Factstone Benchmark(数学)
http://poj.org/problem?id=2661 题意:Amtel在1960年发行了4位计算机,并实行每十年位数翻一番的策略,将最大整数n作为改变的等级,其中n!表示计算机的无符号整数(n ...
- POJ-2661Factstone Benchmark
Factstone Benchmark Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5577 Accepted: 25 ...
随机推荐
- 分布式图数据库 Nebula RC2 发布:增强了 CSV Importer 功能
Nebula Graph 是开源的分布式图数据库,可应用于知识图谱.社交推荐.风控.IoT 等场景. 本次 RC2 主要新增 GO FROM ... REVERSELY 和 GROUP BY 等语句, ...
- python高阶函数——返回函数(闭包)
首先,来看一个一般意义的求和: >>> def cal_sum(*args): ... sum = 0 ... for i in args: ... sum = sum + i .. ...
- Angular常用VSCode插件
1.Angular 8 Snippets(全家桶) 2.TSLint(ts代码规范.错误提示) 3.Material Icon Theme(文件图标) 4.One Dark Pro(主题) 5.Ang ...
- How to: Use XPO Upcasting in XAF 如何:在 XAF 中使用 XPO 强制转换
In this topic, you will learn how to use the Upcasting feature of XPO in XAF. It is useful when you ...
- 分享几个好看又实用的PPT网站~
一,优品PPT[http://www.ypppt.com/] 一个有情怀的免费PPT模板下载网站!拥有非常多很精美的PPT模板,分类齐全,我们可以选择自己喜欢的PPT模板下载套用就可以了. 二,扑奔P ...
- c# 保留2位小数 整数时无小数
对数值保存两位小数,有时是整数时,不需要显示两位小数.例如值为:1.32 保留两位,结果是1.32,值为:2,结果有两种显示,2和2.00 /// <summary> /// 金额 /// ...
- mysql创建用户后无法进入
说明 在mysql中添加用户: #mysql -u root -p >use mysql: >update user set password="" where use ...
- Node.js Error简介以及捕获方式
error的类型nodejs 的error 一般分为四种类型: 1.标准的 JavaScript 错误,例如 EvalError.SyntaxError.RangeError.ReferenceErr ...
- 字典 dict方法
字典 student = {'sId': '1101', 'sName': '张三', 'sClass': '软件测试', 'sColl': '信息技术学院'} # 根据键查询 若不存在会报错 pri ...
- 12C新功能:在线移动分区 (Doc ID 1584032.1)
12C New Feature: Online Move Partition (Doc ID 1584032.1) APPLIES TO: Oracle Database - Enterprise E ...