您的位置:首页 > 其它

poj 1401 Factorial

2011-07-22 14:51 387 查看
#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)


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