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. Python3 shelve模块(持久化)

    shelve模块 也可以序列化Python所有数据类型,而且可以多次序列化;shelve模块通过key-value方式持久化 1.序列化 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

  2. python基础===Windows环境下使用pip install 安装出错"Cannot unpack file"解决办法

    不知道为什么,加了豆瓣镜像源还是不行 这个命令可以解决! pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douba ...

  3. python string 对齐文本的几个方法

    用rjust().ljust()和center()方法对齐文本

  4. api文档工具

    平台选型         Apidoc         文档参考:http://apidocjs.com        优点      文档齐全,操作简单,ui清晰,代码注解查询性强,语言支持多元化, ...

  5. spring restTemplate 用法

    发出get请求,方式一 String url = serverUrl+"/path/path?id={id}"; int i = restTemplate.getForObject ...

  6. printf格式化输出

    基本格式 printf [format] [文本1] [文本2] .. 常用格式替换符 %s 字符串 %f 浮点格式 %c ASCII字符,即显示对应参数的第一个字符 %d,%i 十进制整数 %o 八 ...

  7. vue 文件引入

    直接 <script> 引入 直接下载并用 <script> 标签引入,Vue 会被注册为一个全局变量.重要提示:在开发时请用开发版本,遇到常见错误它会给出友好的警告. 开发环 ...

  8. java常用设计模式学习心得

    学习自:http://shenzhenchufa.blog.51cto.com/730213/161581 代码来自:http://shenzhenchufa.blog.51cto.com/73021 ...

  9. NYOJ 201 作业题

    作业题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 小白同学这学期有一门课程叫做<数值计算方法>,这是一门有效使用数字计算机求数学问题近似解的方法与过 ...

  10. selenium c# 的注意事项

    http://chromedriver.storage.googleapis.com/index.html chromedriver的下载地址http://selenium-release.stora ...