ecnu Problem #3233 N! //qduoj 阶乘问题

来源:互联网 发布:gsm是什么网络制式 编辑:程序博客网 时间:2024/06/03 23:50

N!

Time limit per test: 1.0 seconds

Time limit all tests: 1.0 seconds

Memory limit: 256 megabytes

Give you an integer n, find the maximum k that satisfies

n!mod10k=0

Input

There are several test cases, please process till EOF.

For each test case, there is only one line contains integer n (1n109).

Output

For each test case, output the answer in one line.

Examples

input
25
output
01

Source

2017 华东理工上海高校邀请赛
其实很明显就是求n!后导零的个数

这样题意类似qduoj上的一个题

求后导零的个数,其实也就是求n!素因子分解后5的指数

当时想怎么数位dp,其实根本不需要,

ans=n/5+n/(5*5)+n/(5*5*5)....

n/5代表的是从1到n这些数里可以贡献一个五的数的个数

n/(5*5)代表的是从1到n这些数里可以贡献两个五的数的个数,因为第一步结果已经加了一次,所以只需要再加n/(5*5)即可

#include<bits/stdc++.h>using namespace std;int main(){    long long x;    int T,i; //   cin>>T;    while(cin>>x)    {        long long ans=0;    //    cin>>x;        while(x)        {            ans+=x/5;            x/=5;        }        cout<<ans<<endl;    }    return 0;}

qduoj上改改输入格式即可




0 0
原创粉丝点击