您的位置:首页 > 其它

FZU Number lengths(数学)

2017-03-24 06:46 176 查看

Number lengths

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

1

3

32000

Sample Output

1

1

130271

代码:

#include<stdio.h>
#include<math.h>

#define maxn 1000000+10
double a[maxn]={0};

void init()
{
a[1]=1;
for(int i=2;i<=maxn;i++)
a[i]=a[i-1]+log10(1.0*i);

}

int main()
{
init();
int n;
while(~scanf("%d",&n))
printf("%d\n",(int)a
);
return 0;
}


总结:这么一道大水题,比赛时弄了3个小时没做出来应该够惨了吧

刚开始以为可以递归找规律,结果半点也没找出来0.0

get到了新技能,log10(x)就是求x的十进制位数,log(x)就是求x的二进制位数

刚刚听大神说这题维护前11位也可以过,可是我比赛时想的只是维护首位,然后发现到十几的时候就错了,所以就放弃了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: