且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

POJ1401 数学N!因子分解

更新时间:2022-08-13 16:53:15

这题很水 就是问N!中 末尾0的个数 其实就是问 N!有多少个10相乘 10=2*5 

而N!这些因子化为素因子相乘的形式 2的个数显然比5多 所以只需要计算N!里

有多少个5就行了 比如100里有 5 10 15 20 25 30 35 40 45 50 55 60 65 70 。。。

而25 50 75 100这种里面有两个5 125有3个5 知道这些就能编了。。

#include <iostream>
#include<cstdio>
using namespace std;

int main()
{
    long long a[20];
    a[1]=5;
    for(int i=2; i<=15; i++)
        a[i]=5*a[i-1];
    int n,ans,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        ans=0;
        for(int i=1; i<=13; i++)
            ans+=(n/a[i]);
        printf("%d\n",ans);
    }
    return 0;
}