链接:传送门

题意:一个人自命不凡,他从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. crontab 设置定时任务

    查看当前用户已有的定时任务: crontab -l 编辑crontab: crontab -e 加入需要执行的命令: 0 */4 * * * /www/shwww.net/venv/bin/pytho ...

  2. js 阻止冒泡

    $this.click(function(e){ e.stopPropagation(); });

  3. 使用githug游戏提高git水平

  4. nodejs-函数

    使用表达式定义的函数要提到使用之前,要不然无法解析,自然的function xx(xx)不用,ECMAscript自动提前 with关键字 引入空间命令空间,然后可以直接使用里面的对象了 label标 ...

  5. git常规使用的命令

    注: xxxx代表你的分支名称   1:本地新建一个分支,与远程分支关联: git branch --set-upstream-to origin/xxxx xxxx   2:创建本地分支: git ...

  6. POSIX 线程编程(二)线程建立与终止

    创建与终止线程 线程的管理常用的API有: pthread_create(thread,attr,start_routine,arg) pthread_exit(status) pthread_can ...

  7. mysql开发之---每日一得01

    2015年7月7日------------------------- 1.truncate表会清空建表语句auto_increment的值:某个表的id即是主键也是自增,你能够选择插入随意id值,假设 ...

  8. linux下測试硬盘读写速度

    买了个ssd硬盘,就想着跟普通的机械盘做个比較.由于桌面装的是ubuntu系统,所以就想用linux的命令简单測一下好了 以下是ssd的性能数据: 測试写: xxx@WaitFish:~ > t ...

  9. 利用POI操作不同版本号word文档中的图片以及创建word文档

    我们都知道要想利用java对office操作最经常使用的技术就应该是POI了,在这里本人就不多说到底POI是什么和怎么用了. 先说本人遇到的问题,不同于利用POI去向word文档以及excel文档去写 ...

  10. Dalvik和ART简单介绍

    1.classes.dex文件初识     我们先把QQ_236.apk后缀改为QQ_236.zip,然后解压.发现有一个classes.dex文件,这个classes.dex是java源代码编译后生 ...