这一题让求 n! 的末尾0的个数。
n 有很大。
直接写当然是求不出来的。
那就分析,末尾的0是如何来的。
很显然,由算数基本定理得,任何一个数,都能拆成若干个素数之积。
而素数之积为整10 的只有2和5.
又因为2的个数远远大于5.
所以就转化成找因子数5的个数。
#include <iostream>
#include <stdio.h>
#include <string.h>
#define LL long long
using namespace std;
int main()
{
int T;
LL n;
scanf("%d", &T);
while(T--){
scanf("%lld" ,&n);
LL five=5,cnt=0;
while(five<=n){
cnt+=n/five;
five*=5;
}
printf("%lld\n",cnt);
}
return 0;
}