/*
题目描述:给出一个不大于1e9正整数n,问n!的末尾有几个0
方法:末尾有一个0等价于有素因子当中有1对2和5,所以判断n!的算术分解式当中2和5的指数是多少,其最小值
就是答案。
判断指数大小可以根据定理 n!的分解中素数p的指数大小 x = [n/ p] + [n / p^2] + [n / p^3] + ... + 0;
*/
#pragma warning(disable:4786)
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<sstream>
#define LL long long
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define lson l,m,x<<1
#define rson m+1,r,x<<1|1
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps=1e-8;
int main()
{
int T,n1 ,n2 , temp1 , temp2, sum1 , sum2;
scanf("%d",&T);
while(T--){
scanf("%d",&n1);
n2 = n1;
temp1 = 2; temp2 = 5;
sum1 = 0; sum2 = 0;
while(n1 / temp1 > 0){
sum1 += n1 / temp1 ;
temp1 *= 2;
}
while(n2 / temp2 > 0 ){
sum2 += n2 / temp2;
temp2 *= 5;
}
int ans = min(sum1 , sum2);
printf("%d\n",ans);
}
return 0;
}
nefu118 n!末尾0的个数
最新推荐文章于 2023-08-25 12:35:46 发布