poj 1423 打表/斯特林公式
对于n位数的计算,我们可以采用(int)log10(n) + 1的方法得到n的位数
第一种方法:
对于n!位数的计算,log10(n!) = log10(1) + log10(2) + ... + log10(n)
为防止直接暴力超时这部分运算可以打表等待主程序调用
#include<iostream>
#include<cmath>
using namespace std; const int MAXN = 1e7;
int ans[MAXN +]; void action(int m)//打表计算n!位数,存在ans数组中
{
double d = ;
for(int i = ;i<=m;i++)
{
d += log10(double(i));//累加log10(i)
ans[i] = (int)d + ;//向下取整并+1
}
} int main()
{
int n,m;
cin>>n;
action(MAXN);
while(n--)
{
cin>>m;
cout<<ans[m]<<endl;
}
return ;
}
第二种方法:
对于n!的计算,也可以用斯特林公式:
然后直接计算(int)log10(n!) + 1
#include<iostream>
#include<cmath>
using namespace std; double pi = acos((double)-); int main()
{
int n,m;
cin>>n;
while(n--)
{
cin>>m;
cout<<(int)(log10(sqrt( * m * pi) )+ m * log10(m / exp((double))))+ <<endl;
}
}
poj 1423 打表/斯特林公式的更多相关文章
- POJ 1423:Big Number 求N的阶乘的长度 斯特林公式
Big Number Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27027 Accepted: 8626 Descr ...
- POJ 1423 Big Number
题意:求n阶乘的位数. 解法:斯特林公式,,然后取log10就是位数了,因为精度问题需要化简这个式子,特判1. 代码: #include<stdio.h> #include<iost ...
- Semi-prime H-numbers POJ - 3292 打表(算复杂度)
题意:参考https://blog.csdn.net/lyy289065406/article/details/6648537 一个H-number是所有的模四余一的数. 如果一个H-number是H ...
- POJ 1423 Greatest Common Increasing Subsequence【裸LCIS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1423 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- POJ 1423 斯特林
题意:进制问题 分析: 打表,但是要用不能 long long 型,超内存. n! = log_{10}\sqrt{2{\pi}n}*(\frac{n}e)^n 精度要求 #include <c ...
- POJ 2661Factstone Benchmark(斯特林公式)
链接:传送门 题意:一个人自命不凡,他从1960年开始每10年更新一次计算机的最长储存长数.1960年为4位,每10年翻一倍.给出一个年份y,问这一年计算机可以执行的n!而不溢出的最大n值 思路:如果 ...
- POJ - 3037-Skiing(邻接表+Dijkstra)
Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie ...
- n阶乘,位数,log函数,斯特林公式
一.log函数 头文件: #include <math.h> 使用: 引入#include<cmath> 以e为底:log(exp(n)) 以10为底:log10(n) 以m为 ...
- Hdu 1042 N! (高精度数)
Problem Description Givenan integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input OneN in one ...
随机推荐
- js--Dom Bom操作
– 基础 – 内置对象 ● String对象:处理所有的字符串操作 ● Math对象:处理所有的数学运算 ● Date对象:处理日期和时间的存储.转化和表达 ● Array对象:提供 ...
- qsc oj 22 哗啦啦村的刁难(3)(随机数,神题)
哗啦啦村的刁难(3) 发布时间: 2017年2月28日 20:00 最后更新: 2017年2月28日 20:01 时间限制: 1000ms 内存限制: 128M 描述 哗啦啦村作为喵哈哈村 ...
- 51Nod 1277 字符串中的最大值(KMP,裸题)
1277 字符串中的最大值 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 一个字符串的前缀是指包含该字符第一个字母的连续子串,例如: ...
- Let the Balloon Rise(水)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...
- 浅谈MySQL集群高可用架构
前言 高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.对于一个系统而言,可能包含很多模块,比如前端应用,缓存,数据库,搜索,消息队列等,每个模块都需要做到高可用,才能 ...
- vim&vi在编辑的时候突然卡死,不接收输入问题的解决
多方查找无果,看了官方解释如下: "CTRL-S and CTRL-Q are called flow-control characters. They represent an antiq ...
- windows server 2008使用nginx转发API异常解决办法
公司比较传统,一直使用的JSP做项目,没有遇到过跨域问题. 最近因为公司接到一个微信spa项目,因为考虑到项目需要调用老接口,斗胆选择nginx(1.12.1)做接口转发服务, 开发环境使用的win1 ...
- 怎么去掉织梦网站首页带的index.html/index.php
方法1. 1)在空间面板里面找到默认首页设置: 我们是需要去掉index.html,这时我们只需要把index.html这个把它移到最顶级去就行,然后点击确定,在打开网站刷新下,就基本可以解决了! 其 ...
- Jquery实现两级联动
最后结果如下: 关键代码如下: <select name="customerCondition['credibilityBegin']" id="credibili ...
- Mybatis问题:There is no getter for property named 'unitId' in 'class java.lang.String'
Mybatis遇到的问题 问题: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.re ...