Codeforces 633B A Trivial Problem 【数论】
来源:互联网 发布:node 进入指定目录 编辑:程序博客网 时间:2024/05/04 06:51
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?
The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial.
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.
1
55 6 7 8 9
5
0
The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
题意:问你那些数的阶乘末尾有连续m个0。
lightoj上基本原题:链接
思路:二分一下m和m+1就可以了。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;typedef long long LL;int Count(int n){ int cnt = 0; while(n) { cnt += n / 5; n /= 5; } return cnt;}int Two(int l, int r, int m){ int ans = 0; while(r >= l) { int mid = (l + r) >> 1; int res = Count(mid); if(res < m) l = mid + 1; else if(res >= m) { r = mid - 1; ans = mid; } } return ans;}const int MAXN = 1e9;int main(){ int m; cin >> m; int l = 1, r = MAXN; int L = Two(l, r, m), R = Two(l, r, m+1); //cout << L << " " << R << endl; if(L == 0 || Count(R-1) != m) cout << 0 << endl; else { cout << R - L << endl; for(int i = L; i <= R-1; i++) { if(i > L) cout << " "; cout << i; } cout << endl; } return 0;}
- Codeforces 633B A Trivial Problem 【数论】
- CodeForces 633 B.A Trivial Problem(二分+数论)
- CodeForces 633B A Trivial Problem(找规律)
- CF 633B:A Trivial Problem
- cf 633b A Trivial Problem
- CF 633B A Trivial Problem
- cf 633B A trivial problem
- CodeForces Manthan, Codefest 16 B A Trivial Problem 二分
- CodeForces 633B A Trivial Problem(思维,阶乘 0 的个数)
- Manthan, Codefest 16 -B. A Trivial Problem
- A + B Problem + 数论
- Trivial Problem CodeForces
- A Trivial Problem
- cf A Trivial Problem
- Manthan, Codefest 16 B. A Trivial Problem(数学)
- Problem 1057 a^b(数论)
- hdu 2101 A + B Problem Too(数论)
- 【数论】hdu1402 A * B Problem Plus(FFT)
- 谈谈个人对as3优化见解
- 49.The ORDERS table belongs to the user OE. OE has granted the SELECT privilege on the ORDERS table
- StringBuffer作为形式参数传递
- iOS8 之后对 SearchController的使用
- 定位元素
- Codeforces 633B A Trivial Problem 【数论】
- 最全面的C/C++编码规范总结
- 架构师和开发团队应该如何协作?组织架构怎么设置最好?
- Qt信号函数无法解析的问题解决方法
- <node> tag
- 推荐系统简述(1)基于内容的推荐系统
- Android DisplayingBitmaps笔记
- 多附件上传之动态添加input标签
- Linux系统下自行编译安装MySQL及基础配置全过程解析