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 (1≤n≤109).
Output
For each test case, output the answer in one line.
Examples
input
2 5
output
0 1
Source
2017 华东理工上海高校邀请赛这样题意类似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上改改输入格式即可