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

Manthan, Codefest 16 B. A Trivial Problem 二分 数学的更多相关文章

  1. CF Manthan, Codefest 16 B. A Trivial Problem

    数学技巧真有趣,看出规律就很简单了 wa 题意:给出数k  输出所有阶乘尾数有k个0的数 这题来来回回看了两三遍, 想的方法总觉得会T 后来想想  阶乘 emmm  1*2*3*4*5*6*7*8*9 ...

  2. Manthan, Codefest 16(B--A Trivial Problem)

    B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  3. Manthan, Codefest 16

    暴力 A - Ebony and Ivory import java.util.*; import java.io.*; public class Main { public static void ...

  4. Manthan, Codefest 16 B 数学

    B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. Manthan, Codefest 16 E. Startup Funding ST表 二分 数学

    E. Startup Funding 题目连接: http://codeforces.com/contest/633/problem/E Description An e-commerce start ...

  6. CF Manthan, Codefest 16 G. Yash And Trees 线段树+bitset

    题目链接:http://codeforces.com/problemset/problem/633/G 大意是一棵树两种操作,第一种是某一节点子树所有值+v,第二种问子树中节点模m出现了多少种m以内的 ...

  7. CF #Manthan, Codefest 16 C. Spy Syndrome 2 Trie

    题目链接:http://codeforces.com/problemset/problem/633/C 大意就是给个字典和一个字符串,求一个用字典中的单词恰好构成字符串的匹配. 比赛的时候是用AC自动 ...

  8. Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵

    H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...

  9. Manthan, Codefest 16 G. Yash And Trees dfs序+线段树+bitset

    G. Yash And Trees 题目连接: http://www.codeforces.com/contest/633/problem/G Description Yash loves playi ...

随机推荐

  1. 【Python学习笔记】异常处理try-except

    Python异常处理 我们一般使用try-except语句来进行异常处理. 使用except Exception as err可以统一捕捉所有异常,而也可以分开处理单个异常. # 分开捕捉单个异常 t ...

  2. charger related source code position

    Platform Qualcomm MSM8917 or MSM8937 Source kernel/msm-3.18/drivers/power/qpnp-smbcharger.c kernel/m ...

  3. C语言调用Cmd命令以及执行系统软件

    C语言调用Cmd命令以及执行系统软件 http://blog.csdn.net/qq_16814591/article/details/43676377

  4. mycncart自定义主题

    本文是自己通过其他主题,自学的,如果有什么问题,可以提出建议? 参考资料:opencart官网 www.opencart.com  或 mycncart的官网上的一些教程 www.mycncart.c ...

  5. LeetCode解题报告—— N-Queens && Edit Distance

    1. N-Queens The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no ...

  6. Developer Express控件gridcontrol中gridView的某一个单元格是否可以自由输入

    场景:在Developer Express控件gridcontrol中的gridView中,当医生开的临时医嘱的医嘱类型为"中草药","计价总量"单元格不可以自 ...

  7. scrapy-redis组件的使用

    scrapy-redis是一个基于redis的scrapy组件,通过它可以快速实现简单分布式爬虫程序,该组件本质上提供了三大功能: scheduler - 调度器 dupefilter - URL去重 ...

  8. redis之(十四)redis的主从复制的原理

    一:redis主从复制的原理,步骤.   第一步:复制初始化 --->从redis启动后,会根据配置,向主redis发送SYNC命令.2.8版本以后,发送PSYNC命令. --->主red ...

  9. AC日记——旅游 bzoj 2157

    2157 思路: LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 400005 #define IN ...

  10. JavaScript备忘录-闭包(2)

    闭包的定义 闭包是指函数有自由独立的变量.换句话说,定义在闭包中的函数可以“记忆”它创建时候的环境. 闭包的浅显理解 function makeFunc() { var name = "Mo ...