poj 1401 Factorial

#include <iostream>
using namespace std;
int factorial(int n)
{
int s=0;
while(n>=5)
{
s
+=n/5;
n
=n/5;
}
return s;
}
int main()
{
int t,n;
cin
>>t;
while(t--)
{
cin
>>n;
cout
<<factorial(n)<<endl;
}
}
//逢五进一,比如60
//有 5 10 15 20 25 30 35 40 45 50 55 60 (60/5=12)
//上面的数列除以5后,得 1 2 3 4 5 6 7 8 9 10 11 12
//其中有 5 10 能再被5整除 (12/5=2)
// 25和50 各含有 5 的因子 2 个, (25 ,50 分别乘以 4 , 2 后边就都有2个0)

  

posted on 2011-07-22 14:51  sysu_mjc  阅读(79)  评论(0编辑  收藏  举报

导航