您的位置:首页 > Web前端

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
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: