Manthan, Codefest 16 B. A Trivial Problem 二分 数学
2024-08-25 13:23:46
B. A Trivial Problem
题目连接:
http://www.codeforces.com/contest/633/problem/B
Description
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem?
Input
The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial.
Output
First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order.
Sample Input
1
Sample Output
5
5 6 7 8 9
Hint
题意
让你输出哪些数的阶乘后面恰好有k个0
题解:
首先阶乘后面的0的个数,就是2的因子数和5的因子数的最小值
显然2的因子数肯定比5多,所以不用考虑2,直接考虑5就好了
我是二分找的,当然在这个复杂度下面,直接暴力就好了
代码
#include<bits/stdc++.h>
using namespace std;
long long m;
long long check(long long n)
{
long long num = 0;
while(n)
{
num+=n/5;
n=n/5;
}
return num;
}
int get(long long k)
{
long long l = 0,r = 1e15,ans = r;
while(l<=r)
{
long long mid = (l+r)/2;
if(check(mid)>=k)r=mid-1,ans=mid;
else l=mid+1;
}
return ans;
}
int main()
{
scanf("%lld",&m);
long long ans = get(m),ans2 = get(m+1);
if(check(ans)==m&&check(ans2-1)==m)
{
cout<<ans2-ans<<endl;
for(int i=ans;i<ans2;i++)
cout<<i<<" ";
cout<<endl;
}
else
return puts("0");
}
最新文章
- 创建一个自定义颜色IRgbColor
- Atitit 理解Monad attilax总结
- html5 svg动画
- C++中map的一点疑惑...
- Natural Language Processing Computational Linguistics
- 使用四种框架分别实现百万websocket常连接的服务器
- spring-boot配置外部静态资源的方法
- LCA与RMQ
- linux添加静态路由表,重启继续生效(转载)
- 懒省事的小明--nyoj55
- 1.0.x-学习Opencv与MFC混合编程之---视频运动检测
- NancyFx 2.0的开源框架的使用-Stateless(二)
- html5 file upload and form data by ajax
- delphi
- 剑指offer(8)跳台阶
- oracle生成AWR报告方法
- Java之旅_面向对象_多态
- 分享给大家一个500G.Net ftp资料库
- sqli-labs:5-6,盲注
- 倒计时相关函数 php