Manthan, Codefest 16 B 数学
2016-07-15 23:23
330 查看
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’ 输出个数 并按照升序输出这些数
题解:数学知识 涨姿势
我们知道阶乘下 产生‘0’位只能是 2*5=10产生‘0’位
那么‘0’位的个数取决于‘2’和‘5’的个数
相比之下‘5’的个数更少 所以末尾‘0’的个数取决于阶乘中‘5’的数
所以可以预处理出所有数含有因数‘5’的个数 也就代码中fun的作用
vector存储为一个数x 对应的x!中5的个数也就是结果。
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’ 输出个数 并按照升序输出这些数
题解:数学知识 涨姿势
我们知道阶乘下 产生‘0’位只能是 2*5=10产生‘0’位
那么‘0’位的个数取决于‘2’和‘5’的个数
相比之下‘5’的个数更少 所以末尾‘0’的个数取决于阶乘中‘5’的数
所以可以预处理出所有数含有因数‘5’的个数 也就代码中fun的作用
vector存储为一个数x 对应的x!中5的个数也就是结果。
#include<bits/stdc++.h> #define ll __int64 #define mod 1e9+7 #define PI acos(-1.0) #define bug(x) printf("%%%%%%%%%%%%%",x); #define inf 1e8 using namespace std; #define ll __int64 int fun( int x) { int flag=0; if(x%5==0) { while(x%5==0) { x/=5; flag++; } } return flag; } vector<int>ve[100005]; int m; int main() { scanf("%d",&m); int gg=0; for(int i=1;i<=500000;i++) { gg+=fun(i); if(gg==m) ve[gg].push_back(i); } printf("%d\n",ve[m].size()); if(ve[m].size()) cout<<ve[m][0]; for(int i=1;i<ve[m].size();i++) cout<<" "<<ve[m][i]; cout<<endl; return 0; }
相关文章推荐
- JSON模块
- HTML快速入门 、 文本
- 原子变量(AtomicLong, AtomicInteger, AtomicReference)
- jQuery(不完整,待后续整理补充)
- 前端高级技术考察
- HTML5面向对象的游戏开发简单实例总结
- 剑指offer--20.顺时针打印数组
- js jquery操作的方面xml dom html dom css dom
- js
- js实现动态显示时间(setInterval())
- UVA 1218 Perfect Service
- jQuery(三)——包装集
- JavaScript倒计时setTimeout()和setInterval()
- 深入理解 ButterKnife,让你的程序学会写代码
- js处理数据的方式记录
- 剑指offer之一个数的N次方
- JQuery trigger 个人理解手记
- uglifyjs压缩JS的
- angularJs+MVC+C#学习(二)
- HTML - SELECT默认选中