Number lengths FZU - 1050
N! (N factorial) can be quite irritating and difficult to compute for large values of N. So instead of calculating N!, I want to know how many digits are in it. (Remember that N! = N * (N - 1) * (N - 2) * … * 2 * 1)
Input
Each line of the input will have a single integer N on it 0 < N < 1000000 (1 million). Input is terminated by end of file.
Output
For each value of N, print out how many digits are in N!.
Sample Input
1
3
32000
Sample Output
1
1
130271
//N!位数应该是 log10(1)+log10(2)+···+log10(n) 取整加1,
//注意:log10(n)传入的值必须是double型,所以要进行强制转换!
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;
const int INF=1e9+7;
const int maxn=110;
typedef long long ll;
int n;
int main()
{
while(~scanf("%d",&n))
{
int i,j=0;
double sum=0;
for(i=1; i<=n; i++)
sum+=log10(double(i));
j=(int)sum+1;
printf("%d\n",j);
}
return 0;
}
Number lengths FZU - 1050的更多相关文章
- HDU 1210 Eddy's 洗牌问题(foj1062) || FOJ1050 Number lengths水
麻痹,感冒了. ------------------------------------------------感冒了的分割线------------------------------------- ...
- fzu1050 Number lengths(对数公式)
http://acm.fzu.edu.cn/problem.php?pid=1050 cmath头文件里有两种对数log()和log10(),一个是自然对数,一个是以10为底, 求n!的位数,根据对数 ...
- Mysql-5.6.30卸载
Mysql-5.6.30卸载 一.删除相关文件 rm -rf /var/lib/mysql/mysql (删除数据文件) rm -f /root/.mysql_secure (删除缺 ...
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- fzu 2111 Min Number
http://acm.fzu.edu.cn/problem.php?pid=2111 Problem 2111 Min Number Accept: 572 Submit: 1106Tim ...
- 数学 FZU 2074 Number of methods
题目传送门 /* 数学:假设取了第i个,有C(n-1)(i-1)种取法 则ans = sum (C(n-1)(i-1)) (1<i<=n) 即2^(n-1) */ #include < ...
- FZU - 2109 Mountain Number 数位dp
Mountain Number One integer number x is called "Mountain Number" if: (1) x>0 and x is a ...
- FZU——2111Min Number(多次交换得到最小数,水题)
Problem 2111 Min Number Accept: 760 Submit: 1516 Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- FZU 2109 Mountain Number
http://acm.fzu.edu.cn/problem.php?pid=2109 题意:找出区间[l,r]内满足奇数位的数字大于相邻偶数位数字的个数. 典型的数位dp了,记录一下当前位是奇数位还是 ...
随机推荐
- SQL Server (MSSQLSERVER) 无法启动,错误代码 3417,提示Windows不能在本地计算机启动。
我的电脑为例: 1.打开sql server的安装路径:C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA 2.将 ...
- bzoj3524/2223 [Poi2014]Couriers
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3524 http://www.lydsy.com/JudgeOnline/problem.ph ...
- 你不知道的Static
Static静态字段,静态方法,静态代码块 壹 简介 一些场景下会要求一个类的多个实例共享一个成员变量:有时候想定义一些不和具体对象关联.不需要new就调用的方法 举例:Console类的Write ...
- HTTP、HTTPS
http是一种无状态协议,通过短暂保持浏览器核服务器间通信可以有效减少为保持连接而耗费的额外开销.无状态意味着浏览器和服务器完成一次通信后,连接会释放.在下一次会话发起时,浏览器核服务器端不会记录上一 ...
- Feather包实现数据框快速读写,你值得拥有
什么是Feather? Feature是一种文件格式,支持R语言和Python的交互式存储,速度更快.目前支持R语言的data.frame和Python pandas 的DataFrame. Feat ...
- python基础===基于cv2的播放器
import cv2 import threading import win32gui,win32con class Producer(threading.Thread): ""& ...
- openjudge-NOI 2.6-2728 摘花生
题目链接:http://noi.openjudge.cn/ch0206/2728/ 题解: 某一个点只能从其左边或者上边走过来 f[i][j]存储(i,j)这个点上的结果,即f[i][j]=max(f ...
- Linux中查看CPU信息 (转)
cat /proc/cpuinfo中的信息 processor 逻辑处理器的id. physical id 物理封装的处理器的id. core id 每个核心的id. ...
- centos 下单独安装mysql
https://www.cnblogs.com/running-mydream/p/4666094.html https://www.cnblogs.com/lzj0218/p/5724446.htm ...
- Caffe学习系列(8):solver,train_val.prototxt,deploy.prototxt及其配置
solver是caffe的核心. net: "examples/mnist/lenet_train_test.prototxt" test_iter: 100 test_inter ...