FZU Number lengths(数学)
2017-03-24 06:46
225 查看
Number lengths
Problem DescriptionN! (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位也可以过,可是我比赛时想的只是维护首位,然后发现到十几的时候就错了,所以就放弃了
相关文章推荐
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU 2195 检查站点(数学啊)
- FZU 1076 穿越沙漠(逆推建模)(数学)
- FZU2251OOXX--简单数学题
- FZU OJ 2147 A-B Game (数学水题)
- FZU Problem 2132 LQX的作业 (数学题)
- FZU 1076 穿越沙漠(逆推建模)(数学)
- FZU 2147 A-B Game(数学推导题)