閱讀94 返回首頁    go 技術社區[雲棲]


POJ1401 數學N!因子分解

這題很水 就是問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;
}


最後更新:2017-04-04 07:03:27

  上一篇:go 【最近麵試遇到的一些問題】Java中取小數點後兩位(四種方法)
  下一篇:go 支付寶安全支付服務Android應用開發指南(摘取官方文檔)