您的位置:首页 > 其它

POJ 1401 Factorial

2012-05-06 18:25 323 查看
求 n! 末尾零的个数,在编程之美上看过,其实也不难:求因子2和5的个数取最小值,因为5出现的频率远低于2。

# include <stdio.h>

int solve(int n);

int main()
{
int T, n;

scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
printf("%d\n", solve(n));
}

return 0;
}

int solve(int n)
{
int t;

t = 0;
while (n>0) {n /= 5; t += n;}

return t;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: