阶乘问题

Description

 

 

从输入文件中读取一个数n,求出n!中末尾0的个数。

 

Input

 

 

输入有若干行。每一行上有一个整数m,指明接下来的数字的个数。然后是m行,每一行包含一个确定的正整数n,1<=n<=1000000000

 

Output

 

 

对输入行中的每一个数据n,输出一行,其内容是n!中末尾0的个数。

 

Sample Input

3 3 100 1024

Sample Output

0 24 253
 
 
全都看有几个5
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(void){
  int n, m;
  scanf("%d", &m);
  while (m--){
    scanf("%d", &n);
    int t = 5, cnt = 0;
    while (t <= n){
       cnt += n/t; t *= 5;
    }
    printf("%d\n", cnt);
  }
  return 0;
}

  

posted on 2014-06-22 15:15  天元突破  阅读(194)  评论(0编辑  收藏  举报

导航