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的更多相关文章

  1. HDU 1210 Eddy's 洗牌问题(foj1062) || FOJ1050 Number lengths水

    麻痹,感冒了. ------------------------------------------------感冒了的分割线------------------------------------- ...

  2. fzu1050 Number lengths(对数公式)

    http://acm.fzu.edu.cn/problem.php?pid=1050 cmath头文件里有两种对数log()和log10(),一个是自然对数,一个是以10为底, 求n!的位数,根据对数 ...

  3. Mysql-5.6.30卸载

    Mysql-5.6.30卸载 一.删除相关文件 rm  -rf  /var/lib/mysql/mysql   (删除数据文件) rm  -f  /root/.mysql_secure    (删除缺 ...

  4. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  5. fzu 2111 Min Number

      http://acm.fzu.edu.cn/problem.php?pid=2111  Problem 2111 Min Number Accept: 572    Submit: 1106Tim ...

  6. 数学 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 < ...

  7. FZU - 2109 Mountain Number 数位dp

    Mountain Number One integer number x is called "Mountain Number" if: (1) x>0 and x is a ...

  8. FZU——2111Min Number(多次交换得到最小数,水题)

    Problem 2111 Min Number Accept: 760    Submit: 1516 Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  9. FZU 2109 Mountain Number

    http://acm.fzu.edu.cn/problem.php?pid=2109 题意:找出区间[l,r]内满足奇数位的数字大于相邻偶数位数字的个数. 典型的数位dp了,记录一下当前位是奇数位还是 ...

随机推荐

  1. Python学习笔记(三十九)— 内置模块(8)XML基础

    摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432002075 ...

  2. 【BZOJ】4756: [Usaco2017 Jan]Promotion Counting

    [题意]带点权树,统计每个结点子树内点权比它大的结点数. [算法]线段树合并 [题解]对每个点建权值线段树(动态开点),DFS中将自身和儿子线段树合并后统计. 注意三个量tot,cnt,tots,细心 ...

  3. POJ 1050 To the Max (最大子矩阵和)

    题目链接 题意:给定N*N的矩阵,求该矩阵中和最大的子矩阵的和. 题解:把二维转化成一维,算下就好了. #include <cstdio> #include <cstring> ...

  4. CodeForces 1011B

    Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...

  5. 【leetcode 简单】第四十题 求众数

    给定一个大小为 n 的数组,找到其中的众数.众数是指在数组中出现次数大于 ⌊ n/2 ⌋ 的元素. 你可以假设数组是非空的,并且给定的数组总是存在众数. 示例 1: 输入: [3,2,3] 输出: 3 ...

  6. HDU 2159 FATE (dp)

    题目链接 Problem Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务.久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最 ...

  7. HDU 1394 Minimum Inversion Number (树状数组)

    题目链接 Problem Description The inversion number of a given number sequence a1, a2, ..., an is the numb ...

  8. 工作中常用的Git操作--------(一)

    今天主要记录一下平常工作当中使用的git操作: 1.git的安装这里省略: 2.git的操作指令: 在项目开发中,经常是拉去经理已经搭建好的一个项目,也就是给我们一个git地址.比如:http://g ...

  9. typeof运算符

    javascript中typeof用来判断一个变量或表达式的数据类型. typeof 返回值有六种可能: "number," "string," "b ...

  10. 59、有用过with statement吗?它的好处是什么?

    python中的with语句是用来干嘛的?有什么作用? with语句的作用是通过某种方式简化异常处理,它是所谓的上下文管理器的一种 用法举例如下: with open('output.txt', 'w ...