异想天开

What's the true meaning of light, Could you tell me why

阶乘的0

日期:2015-02-13 16:35:49
  
最后更新日期:2015-02-13 17:10:00
【技术】
计算n!的十进制表示最后有多少个0
http://acm.nyist.net/JudgeOnline/problem.php?pid=84
代码:即计算阶乘因子5的个数 [code lang="cpp"]
#include<iostream>
#include<map>
#include<vector>
#include <algorithm>
#include<stdio.h>
#include<memory.h>
#include<set>

using namespace std;
const int MAX = 10000000;
char isfive[MAX];

int main()
{
int n,c,sum;
for( int i=5; i<=MAX;i*=5 ){
int END=MAX/i;
for( int j=1; j<=END; j++ ){
isfive[j*i]+=1;
}
}
scanf("%d",&c);
while(c-->0){
sum=0;
scanf("%d",&n);
for( int i=5;i<=n;i+=5){
sum += isfive[i];
}
printf("%d\n",sum);
}
return 0;
}
[/code]