Number lengths

原创 2018年04月17日 21:10:53

 Problem Description

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

13 32000

Sample Output

1 1 130271  

题意:求N!(N的阶乘)有几位数字。    提示:利用log函数!!

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        double a=1;
        int i;
        for(i=1;i<=n;i++)
        {
            a=a+log(i)/log(10);
        }
        int ans=a;
        printf("%d\n",ans);
    }
}

实战COM(07)----COM+的特性之建立者字符串

本文欢迎转载,唯请注明出处及作者 blackcolor@263.net---------------------------------------------------              ...
  • blackcolor
  • blackcolor
  • 2001-08-03 10:12:00
  • 780

Number lengths FZU - 1050

N! (N factorial) can be quite irritating and difficult to compute for large values of N. So instead ...
  • Tanglouis2017
  • Tanglouis2017
  • 2017-03-24 17:31:18
  • 202

fzu 1050 Number lengths

题目链接:fzu 1050 Number lengths 题目大意:计算n!有多少位数。 解题思路:ans = log10(n!) =...
  • u011328934
  • u011328934
  • 2013-12-14 23:38:32
  • 960

codeforces 水题 37A-Towers

A. Towerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstan...
  • duanghaha
  • duanghaha
  • 2018-03-09 08:37:48
  • 17

FZU 1050 Number lengths (思维题)

Problem Description N! (N factorial) can be quite irritating and difficult to compute for large v...
  • xiaosshhaa
  • xiaosshhaa
  • 2017-03-24 11:10:35
  • 167

HDU 1518

Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...
  • u013742332
  • u013742332
  • 2014-03-20 21:19:03
  • 367

基础搜索算法题解(A-C)

搜索专项
  • Tc_To_Top
  • Tc_To_Top
  • 2015-01-24 01:16:31
  • 899

foj1050 Number lengths

1050 Number lengths" TITLE="foj  1050 Number lengths" /> Problem 1050 Number lengths Accept: 858  ...
  • wwk0125
  • wwk0125
  • 2014-03-24 12:06:10
  • 311

FZU Number lengths(数学)

Number lengthsProblem DescriptionN! (N factorial) can be quite irritating and difficult to compute f...
  • blessLZH0108
  • blessLZH0108
  • 2017-03-24 06:46:55
  • 412

Number lengths FZU - 1050

N! (N factorial) can be quite irritating and difficult to compute for large values of N. So instead ...
  • qq_35806592
  • qq_35806592
  • 2017-03-23 23:03:57
  • 82
收藏助手
不良信息举报
您举报文章:Number lengths
举报原因:
原因补充:

(最多只允许输入30个字)