【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 ...
随机推荐
- Prometheus学习系列(八)之Prometheus API说明
前言 本文来自Prometheus官网手册 和 Prometheus简介 HTTP API 在Prometheus服务器上的/api/v1下可以访问当前稳定的HTTP API. 将在该端点下添加任何非 ...
- 基于Maven 的 Spring MVC
Spring MVC 他是基于MVC的设计模式做出来的,他是Spring对Servlet的进一步的封装 MVC:Model View Controller 如何使用Spring MVC?(Spri ...
- MyBatis初体验
一.MyBatis 1.简介 曾命名IBatis(老版本), 交给Google维护后,改名为MyBatis(新版本).学习文档: https://mybatis.org/mybatis-3/zh/in ...
- JDK8,Optional
作为程序员,你肯定遇到过NullPointerException, 这个异常对于初出茅庐的新人, 还是久经江湖的老手都是不可避免的痛, 可又是那么的无能为力,为了解决它,你只能在使用某个值之前,对其 ...
- QT--吃月亮小游戏
QT--吃月亮小游戏 简介: 该设计使用了鼠标事件.键盘事件.绘图事件,可通过鼠标或者方向键控制人物移动吃到月亮 代码: 1.widget.h文件: #ifndef WIDGET_H #define ...
- Linux笔记15 使用Apache服务部署静态网站。
配置服务文件参数Linux系统中的配置文件 服务目录 /etc/httpd 主配置文件 /etc/httpd/conf/httpd.conf 网站数据目录 /var/www/html 访问日志 /va ...
- centos和Ubuntu系统最小化安装基础命令
CentOS系统常用的基础软件如下 yum install vim iotop bc gcc gcc-c++ glibc glibc-devel pcre \ pcre-devel openssl o ...
- java全栈项目
文档地址:https://course.7yue.pro/lin/sleeve/ http://talelin.unna.com.cn/ 1.小程序里,我把结构分为三部分:wxml(view).pag ...
- 计算机网络知识之TCP/IP协议簇
OSI参考模型 OSI的来源 OSI(Open System Interconnect),即开放式系统互联. 一般都叫OSI参考模型,是ISO(国际标准化组织)组织在1985年研究的网 ...
- 手机投屏工具与HOSTS切换工具
ApowerMirror windows -->switchhosts