Manthan, Codefest 16 B. A Trivial Problem 二分 数学
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 二分 数学的更多相关文章
- CF Manthan, Codefest 16 B. A Trivial Problem
数学技巧真有趣,看出规律就很简单了 wa 题意:给出数k 输出所有阶乘尾数有k个0的数 这题来来回回看了两三遍, 想的方法总觉得会T 后来想想 阶乘 emmm 1*2*3*4*5*6*7*8*9 ...
- 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 ...
- Manthan, Codefest 16
暴力 A - Ebony and Ivory import java.util.*; import java.io.*; public class Main { public static void ...
- Manthan, Codefest 16 B 数学
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Manthan, Codefest 16 E. Startup Funding ST表 二分 数学
E. Startup Funding 题目连接: http://codeforces.com/contest/633/problem/E Description An e-commerce start ...
- CF Manthan, Codefest 16 G. Yash And Trees 线段树+bitset
题目链接:http://codeforces.com/problemset/problem/633/G 大意是一棵树两种操作,第一种是某一节点子树所有值+v,第二种问子树中节点模m出现了多少种m以内的 ...
- CF #Manthan, Codefest 16 C. Spy Syndrome 2 Trie
题目链接:http://codeforces.com/problemset/problem/633/C 大意就是给个字典和一个字符串,求一个用字典中的单词恰好构成字符串的匹配. 比赛的时候是用AC自动 ...
- Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵
H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...
- 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 ...
随机推荐
- ms17-010 攻击win7漏洞复现
只是为了好玩重新写一篇.利用还是很简单的. 将下载下来的rb放置在:/usr/share/metasploit-framework/modules/exploits/windows/smb/ 目录下 ...
- Android 聊天软件客户端
1.代码架构图 2.qq.model层 3.qq.app层 4.qq.Constatnt层 5.qq.util层 6.qq.broadcast层 7.qq.control层 8.qq.view层 9. ...
- 【bzoj4373】算术天才⑨与等差数列
同之前那道由乃题,可以认为由乃题是这题的特殊情况…… 维护方法是同样的,维护区间和,区间平方和即可. 注意特判一个数(其实没有必要) #include<bits/stdc++.h> ; u ...
- Load balancer does not have available server for client:xxx
今天在搭建一个springcloud项目在搭建以zuul为网关的时候,项目抛了一个异常, com.netflix.zuul.exception.ZuulException: Forwarding er ...
- aspxpivotgrid排序
protected virtual void SetSortBySummary() { foreach (PivotGridField field in grid.Fields) { if (fiel ...
- django “如何”系列9:三合一:利用遗留的数据库、输出csv和输出pdf
如何集成遗留的数据库 django在适合开发新应用的同时,可以可以集成以前遗留的数据库,下面是如何集成一个已经存在的数据库的流程. 给定你的数据库的参数 你需要告诉django你的数据库连接参数以及数 ...
- python读写hdf5及cdf格式文件
Python write and read hdf5 file http://stackoverflow.com/questions/20928136/input-and-output-numpy-a ...
- AC日记——聪明的质监员 洛谷 P1314
聪明的质监员 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 #define l ...
- 03 java 基础:注释 关键字 标识符 JShell
Java 10 中已有 Jshell 工具,方便用户在其中直接输入相关 java 代码. 注释:java 中分为单行注释 // 多行注释 /* */ 文档注释 /** */ 关键字:在 ...
- 五十八 数据库访问使用SQLite
SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成. Python就 ...