Codeforces 633B A Trivial Problem 【数论】
2016-02-29 21:03
344 查看
B. A Trivial Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
output
input
output
Note
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代码:
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
1
output
5 5 6 7 8 9
input
5
output
0
Note
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; }
相关文章推荐
- [LeetCode]28. Implement strStr()
- MEID与IMEI
- LVS + Keeplaved 配置
- UITableView的性能优化,让TableView更加的丝滑!
- poj-1321-棋盘问题(dfs)
- 2012年 蓝桥杯C++省赛 古堡算式
- 蓝桥杯 李白打酒
- Git初体验之远程仓库
- Java回调
- Codeforces 633A Ebony and Ivory 【水题】
- windows基础编程----第三篇(窗口的消息处理机制)
- leetcode刷题,总结,记录,备忘, 279
- AudioUnit的学习
- c++单例 通过cocos2dx重现c++单例—— c++语法复习
- 226. Invert Binary Tree
- 164. Maximum Gap
- Socket通讯解决并发采用线程池
- Android 仿照微信发说说,既能实现拍照,选图库,多图案上传 使用Retrofit2.0技术
- jquery ajax异步请求
- C++智能指针简单剖析