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"); }

最新文章

  1. 创建一个自定义颜色IRgbColor
  2. Atitit 理解Monad attilax总结
  3. html5 svg动画
  4. C++中map的一点疑惑...
  5. Natural Language Processing Computational Linguistics
  6. 使用四种框架分别实现百万websocket常连接的服务器
  7. spring-boot配置外部静态资源的方法
  8. LCA与RMQ
  9. linux添加静态路由表,重启继续生效(转载)
  10. 懒省事的小明--nyoj55
  11. 1.0.x-学习Opencv与MFC混合编程之---视频运动检测
  12. NancyFx 2.0的开源框架的使用-Stateless(二)
  13. html5 file upload and form data by ajax
  14. delphi
  15. 剑指offer(8)跳台阶
  16. oracle生成AWR报告方法
  17. Java之旅_面向对象_多态
  18. 分享给大家一个500G.Net ftp资料库
  19. sqli-labs:5-6,盲注
  20. 倒计时相关函数 php

热门文章

  1. mssql注入中的储存用法删除与恢复
  2. java===java基础学习(15)---抽象,接口
  3. pandas+sqlalchemy 保存数据到mysql
  4. JavaScript 正则表达式的入门与使用
  5. 高德地图web 端智能围栏
  6. Zookeeper 入门第一篇
  7. BlockingQueue drainTo()
  8. AC日记——[HNOI2008]GT考试 bzoj 1009
  9. AC日记——【模板】分块/带修改莫队(数颜色) 洛谷 P1903
  10. ARM芯片stm32中的AHB和APB