NEFU 118

其实一道公式题:

n!中素数i的幂为:

[n/i]+[n/i^2]+[n/i^3]+[n/i^4]+......

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

long long n;

int main(){
	long long two,five; int t;
	scanf("%d",&t);
	while(t--){
		scanf("%lld",&n);
		two=five=0;
		for(long long i=2;i<=n;i*=2)
		two+=(n/i);
		for(long long i=5;i<=n;i*=5)
		five+=(n/i);
		printf("%lld\n",two>five?five:two);
	}
	return 0;
}

  

posted @ 2014-08-28 09:19  chenjunjie1994  阅读(122)  评论(0编辑  收藏  举报