链接:传送门

题意:一个人自命不凡,他从1960年开始每10年更新一次计算机的最长储存长数。1960年为4位,每10年翻一倍。给出一个年份y,问这一年计算机可以执行的n!而不溢出的最大n值

思路:如果直接比较 2^x - 1 < n! 是一定会溢出的,所以不妨对左右取对数,使之变为 x*log10(2) < log10(n!) 。

使用斯特林公式优化一下n!的计算就能解决这个问题了。


/*************************************************************************
> File Name: poj2661.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年04月26日 星期三 22时52分03秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std; #define PI 3.1415926535
int y , n;
int main(){
double t = log10(2);
while(~scanf("%d",&y) && y){
int d = (y-1960)/10;
int x = pow(2.0,d)*4;
double tmp;
for(n = 1; 1 ; n++){
tmp = log10( sqrt(2*PI*n)) + n*log10(n*1.0/exp(1));
if(x*t<tmp) break;
}
printf("%d\n",n-1);
}
return 0;
}

POJ 2661Factstone Benchmark(斯特林公式)的更多相关文章

  1. poj 1423 打表/斯特林公式

    对于n位数的计算,我们可以采用(int)log10(n) + 1的方法得到n的位数 第一种方法: 对于n!位数的计算,log10(n!) = log10(1) + log10(2) + ... + l ...

  2. 【poj2661】Factstone Benchmark(斯特林公式)

    传送门 题意: 给出\(x,x\leq 12\),求最大的\(n\),满足\(n!\leq 2^{2^x}\). 思路: 通过斯特林公式: \[ n!\approx \sqrt{2\pi n}\cdo ...

  3. POJ 1423:Big Number 求N的阶乘的长度 斯特林公式

    Big Number Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27027   Accepted: 8626 Descr ...

  4. poj 2661 Factstone Benchmark (Stirling数)

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

  5. poj 2661 Factstone Benchmark

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

  6. poj 1502 最短路+坑爹题意

    链接:http://poj.org/problem?id=1502 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  7. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

  8. (poj)1502 MPI Maelstrom

    题目链接:http://poj.org/problem?id=1502 Description BIT has recently taken delivery of their processor A ...

  9. POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)

    POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...

随机推荐

  1. SQLAlchemy小知识点

    1.创建数据库模型的时候增加添加上注释SQLAlchemy1.2新增了comment参数telephone = db.Column(db.String(11), nullable=False, com ...

  2. Python设计模式--单例模式(懒汉式)

    1. 单例模式 --> 单一(唯一)的实例. 在整个运行时间内, 内存中只有一个对象, 一般该对象涉及网络,资源等操作. 2. 单例模式一般分为懒汉式和饿汉式 懒汉式内存占用更加合理. 3. 调 ...

  3. CNN实现terecord、数据集、模型训练

    AlexNet(Alex Krizhevsky,ILSVRC2012冠军)适合做图像分类.层自左向右.自上向下读取,关联层分为一组,高度.宽度减小,深度增加.深度增加减少网络计算量. 训练模型数据集 ...

  4. jQuery(基础dom及css操作)

    设置元素内容 元素属性操作 ---------- 元素样式操作 ---------------- 对象数组的遍历 测试代码: $(function () { var v=$('div').css([' ...

  5. ibatis的批处理

    (1)spring模式:尽管spring已经配置了事务,但以下代码中还是要设置事务,不然batch不会起作用;另外这里虽然设了一下事务处理,但对全局事务并不会造成影响;注:不启用事务将建立多次连接,这 ...

  6. [GraphQL] Mutations and Input Types

    Sometimes, you want to resues object type when doing mutation, you can use 'input' type to help: inp ...

  7. Hadoop高速入门

    Hadoop高速入门 先决条件 支持平台 GNU/Linux是产品开发和执行的平台. Hadoop已在有2000个节点的GNU/Linux主机组成的集群系统上得到验证. Win32平台是作为开发平台支 ...

  8. Project Euler:Problem 37 Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  9. Http multipart/form-data多参数Post方式上传数据

    最近,工作中遇到需要使用java实现http发送get.post请求,简单的之前经常用到,但是这次遇到了上传文件的情况,之前也没深入了解过上传文件的实现,这次才知道通过post接口也可以,是否还有其他 ...

  10. oracle 11gR2 如何修改 private ip

    1.1    修改 private ip1.1.1  确保crs集群是打开的可以用olsnodes –s 检查集群的状态./olsnodes -sP570a ActiveP570b Active1.1 ...