51nod N的阶乘
来源:互联网 发布:grub4dos 引导linux 编辑:程序博客网 时间:2024/05/21 10:54
输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。Input第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000)第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)Output共T行,输出对应的阶乘的长度。Input示例3456Output示例233
没什么好说的,斯特林近似公式。N=1的时候特判一下。不过没判也能够,应该是没有这组数据。下面是计算N!的位数的公式:
#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<cctype>#include<cmath>#include<ctime>#include<string>#include<stack>#include<deque>#include<queue>#include<list>#include<set>#include<map>#include<cstdio>#include<limits.h>#define MOD 1000000007#define fir first#define sec second#define fin freopen("/home/ostreambaba/文档/input.txt", "r", stdin)#define fout freopen("/home/ostreambaba/文档/output.txt", "w", stdout)#define mes(x, m) memset(x, m, sizeof(x))#define Pii pair<int, int>#define Pll pair<ll, ll>#define INF 1e9+7#define Pi 4.0*atan(1.0)#define lowbit(x) (x&(-x))#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef long long ll;typedef unsigned long long ull;const double eps = 1e-12;//const int maxn = 1000100;using namespace std;#include<stdio.h>#include<algorithm>#include<iostream>#include<string.h>#include<math.h>using namespace std;inline int read(){ int x(0),f(1); char ch=getchar(); while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();} while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}ll Stirling(int n){ if(1 == n){ return 1; } ll res = log10(n*2*Pi)/2 + (ll)n*log10(n/exp(1.0)) + 1; return res;}int main(){ int T, n; T = read(); while(T--){ n = read(); printf("%lld\n", Stirling(n)); } return 0;}
0 0
- 51nod N的阶乘
- 51nod N的阶乘
- 51nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51nod N的阶乘 (大数优化)
- 51Nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51Nod-1057-N的阶乘
- 51Nod-1059-N的阶乘 V2
- 51 nod 1057 n的阶乘
- 51Nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51nod 1058 N的阶乘的长度
- 51nod 1058 N的阶乘的长度
- 51NOD 求n的阶乘的长度(斯特林公式)
- HDU 5889 Barricade 最短路最小割 -
- 泊松分布采样 (Poisson-Disk-Sample)代码及详细注释【OpenCV】
- 面向服务的体系结构与企业体系结构,第 2 部分: 相似点与不同处
- 模型构建问题
- 在Android App里实现语言切换
- 51nod N的阶乘
- POJ1088滑雪(记忆化搜索与dp)
- 10fitsSystemWindows对CoordinatorLayout的影响
- Java中什么是接口回调?
- 百度地图定位
- 程序员职业发展:项目经理、技术经理还是产品经理
- uva11624 Fire! BFS搜索 TWT Tokyo Olympic 2combo-2
- JAVA基础知识点(四)--super,方法重写,instanceof
- JavaScript面向对象编程之创建对象