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 ...
随机推荐
- mongodb数据库安装
mongodb的安装 1,下载安装包: http://www.runoob.com/mongodb/mongodb-window-install.html 2,安装至: D:\MongoDB,将 ...
- MkDocs项目文档生成器
简介 安装 我的配置 Chocolatey 简介 - Windows的包管理器 官方网址 安装 注意事项 Python 简介 安装 Pip 简介-Python的包管理器 升级 MkDocs的安装 使用 ...
- 【批处理学习笔记】第十二课:常用DOS命令(2)
文件管理type 显示文本文件的内容.copy 将一份或多份文件复制到另一个位置.del 删除一个或数个文件.move 移动文件并重命名文件和目录.(Windows XP Home Edition中没 ...
- UVA11636-Hello World!-水题
Hello World! Time limit: 1.000 seconds When you first made the computer to print the sentence "H ...
- [bzoj1227] [SDOI2009]虔诚的墓主人
终于填上了这个万年巨坑....从初二的时候就听说过这题...然后一直不敢写QAQ 现在感觉也不是很烦(然而我还是写麻烦了 离散化一波,预处理出组合数什么的.. 要维护对于当前行,每列上方和下方节点凑出 ...
- Can you find it?(哈希)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Time Limit: 10000/3000 MS (Java ...
- Winform 控件的入门级使用(一)
开始总结一下控件的基本用法,方便以后查阅. 一.Label Label 的使用频率很高,基本上也没有什么难度. #region Winform //label label.Text = "这 ...
- java中强,软,弱,虚引用 以及WeakHahMap
java中强,软,弱,虚引用 以及WeakHahMap 一:强软引用: 参考:http://zhangjunhd.blog.51cto.com/113473/53092/进行分析 packa ...
- 基于 fireasy 构建的 asp.net core 示例
最近花时间弄了一个关于fireasy使用的demo,已放到 github 上供大家研究,https://github.com/faib920/zero 该 demo 演示了如何使用 fireasy 创 ...
- block一点也不神秘————如何利用block进行回调
我们在开发中常常会用到函数回调,你可以用通知来替代回调,但是大多数时候回调是比通知方便的,所以何乐而不为呢?如果你不知道回调使用的场景,我们来假设一下: 1.我现在玩手机 2.突然手机没有电了 3.我 ...