Snow祝你元宵节快乐! Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic PRoblem Description
元宵节到了,Snow 也准备一掷千金买汤圆来庆祝元宵节。Snow 非常慷慨,他将分享给你一定数量的汤圆,那么是多少个汤圆呢?答案是 n!(n 的阶乘)…… 嘻嘻别傻了,Snow 要分享给你的是 n! 的位数个汤圆,但前提是你得求出 n! 有多少位哦。
Input
输入数据有多组(数据组数不超过 500),到 EOF 结束。 每组数据输入 n (1 <= n <= 500)。
Output
对于每组数据,输出一行,表示 n! 的位数。
Example Input
1
20
Example Output
1
19
学长解析:考虑 log(a*b) = log(a) + log(b),N! 的位数就是 log1 + log2 + log3 + … + logn,将得到的数进一再加一即可。
thought: 明显是个数学题。。。。。 题目会卡超时。。。递归不行,所以应该就是找公式了。。 log10(a*b)=log10(a)+log10(b);
#include <stdio.h>#include <math.h>int main(){ int n; while(~scanf("%d", &n)) { int i; double ans=0; for(i=1; i<=n; i++)ans+=log10((double)i); printf("%d/n", (int)ans+1); }}Download as text新闻热点
疑难解答