hdu 1018
2016-07-13 10:23
295 查看
题目概述
给定数字N,求N!中所含数字的位数时限
1000ms/2000ms输入
第一行正整数times,其后times行,每行一个正整数N限制
1<=N<=1e7输出
每行一个数,如题目要求所示样例输入
310
20
100000
样例输出
719
456574
讨论
如果你不知道斯特林(stirling)公式是什么,这个题八成是做不出来的这便是斯特林公式,直接对其两部分求两个对数,加和即可
题解状态
0MS,1720K,581 B,C++题解代码
#include<stdio.h> #include<string.h> #include<algorithm> #include<vector> using namespace std; #define INF 0x3f3f3f3f #define MAXN 22 #define memset0(a) memset(a,0,sizeof(a)) const double pi = atan(1.0) * 4; const double e = 2.718281828459;//要么背过 要么去百度然后背过 库里没有这个东西 int fun(int N) { double a = 0.5*log10(2 * pi*N); double b = N*log10(N / e); return ceil(a + b);//向上取整 原因不必多言 } int main(void) { //freopen("vs_cin.txt", "r", stdin); //freopen("vs_cout.txt", "w", stdout); int times; scanf("%d", ×);//input while (times--) { int N; scanf("%d", &N);//input printf("%d\n", fun(N));//output } }
EOF
相关文章推荐
- 共享锁和排它锁
- spark新能优化之序列化
- 用tornado实现一个简单的websocket样例
- MVC 之 EF框架简介
- 面试经验
- 网络知识
- 在 Linux 下使用任务管理器
- Static关键字所有用法详解
- SSH问题总结(1)_Spring注入问题
- 2014 鞍山区域赛 C HDU5072 Coprime 莫比乌斯/容斥+同色三角形
- 【Unity3D自学记录】鼠标拖拽物体移动
- 如何设置感兴趣的区域ROI
- 脱壳基础
- Druid连接池在spring中的配置
- c/c++ 动态内存配置的使用原则
- iOS推送通知的证书设置
- win 安装plsql的步骤
- OC 成员变量和属性的区别
- MarkdownPad2.5 注册码
- One Step By One Step 解析OkHttp3 - Dispatcher (一)