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 mzeroes. Then print
these k integers in increasing order.

Example
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.

#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=0x3f3f3f3f;
const int maxn=500100; int m,cnt;
int num[maxn],a[maxn];
int fun(int n)
{
int ans=0;
while(n)
{
n/=5;
ans+=n;
}
return ans;
} int main()
{
for(int i=0; i<maxn; i++)
a[i]=fun(i);
while(~scanf("%d",&m))
{
cnt=0;
int i;
for(i=0; i<maxn; i++)
{
if(a[i]==m)
{
num[cnt++]=i;
}
}
printf("%d\n",cnt);
if(cnt)
{
for(i=0; i<cnt; i++)
{
if(i) printf(" ");
printf("%d",num[i]);
}
printf("\n");
}
}
return 0;
} #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int MAXN = 1e9; int fun(int n)
{
int cnt = 0;
while(n)
{
n/=5;
cnt+=n;
}
return cnt;
}
int Two(int l, int r, int m)
{
int ans = 0;
while(r >= l)
{
int mid = (l + r) >> 1;
int res = fun(mid);
if(res < m)
l = mid + 1;
else if(res >= m)
{
r = mid - 1;
ans = mid;
}
}
return ans;
}
int main()
{
int m;
while(cin >> m)
{
int l = 1, r = MAXN;
int L = Two(l, r, m), R = Two(l, r, m+1);
if(L == 0 || fun(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;
}

cf 633B A trivial problem的更多相关文章

  1. Codeforces 633B A Trivial Problem

    B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. CodeForces - 633B A Trivial Problem 数论-阶乘后缀0

    A Trivial Problem Mr. Santa asks all the great programmers of the world to solve a trivial problem. ...

  3. codeforces 633B B. A Trivial Problem(数论)

    B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. 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 ...

  5. 把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend

    //把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend //dp[i][j]:把第i个数转成第j小的数,最小花费 //此题与po ...

  6. Manthan, Codefest 16 B. A Trivial Problem 二分 数学

    B. A Trivial Problem 题目连接: http://www.codeforces.com/contest/633/problem/B Description Mr. Santa ask ...

  7. E - A Trivial Problem(求满足x!的尾数恰好有m个0的所有x)

    Problem description Mr. Santa asks all the great programmers of the world to solve a trivial problem ...

  8. CF Manthan, Codefest 16 B. A Trivial Problem

    数学技巧真有趣,看出规律就很简单了 wa 题意:给出数k  输出所有阶乘尾数有k个0的数 这题来来回回看了两三遍, 想的方法总觉得会T 后来想想  阶乘 emmm  1*2*3*4*5*6*7*8*9 ...

  9. 【dp/贪心】CF 780 (Div. 3), problem: (C) Get an Even String

    Problem - C - Codeforces 难度: 1300 input 6 aabbdabdccc zyx aaababbb aabbcc oaoaaaoo bmefbmuyw output ...

随机推荐

  1. iOS 监听UILabel点击

    label.userInteractionEnabled = YES; // 一定要设置 [label addGestureRecognizer:[[UITapGestureRecognizer al ...

  2. 重构改善既有代码设计--重构手法18:Self Encapsulate Field (自封装字段)

    你直接访问一个值域(field),但与值域之间的耦合关系逐渐变得笨拙. 为这个值域建立取值/设值函数(getting/setting methods),并且只以这些函数来访问值域. private i ...

  3. cropper.js 跨域问题

    this.$clone = $clone = $('<img>'); $clone.one('load', $.proxy(function () { var naturalWidth = ...

  4. 【BZOJ】4756: [Usaco2017 Jan]Promotion Counting

    [题意]带点权树,统计每个结点子树内点权比它大的结点数. [算法]线段树合并 [题解]对每个点建权值线段树(动态开点),DFS中将自身和儿子线段树合并后统计. 注意三个量tot,cnt,tots,细心 ...

  5. 《Troubleshooting SQL Server》读书笔记-CPU使用率过高(上)

    第三章 High CPU Utilization. CPU使用率过高问题很容易被发现,但是诊断却不是很容易.CPU使用过高很多时候会成为其它问题的替罪羊,所以在确认和故障诊断时要抽丝剥茧. 调查CPU ...

  6. HNU Joke with permutation (深搜dfs)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=13341&courseid=0 Joke with pe ...

  7. C++之 extern C的作用详解

    extern "C"的主要作用就是为了能够正确实现C++代码调用其他C语言代码.加上extern "C"后,会指示编译器这部分代码按C语言的进行编译,而不是C+ ...

  8. python基础===map, reduce, filter的用法

    filter的用法: 这还是一个操作表list的内嵌函数'filter' 需要一个函数与一个list它用这个函数来决定哪个项应该被放入过滤结果队列中遍历list中的每一个值,输入到这个函数中如果这个函 ...

  9. java中String的==和equals的区别

    首先看代码1: public static void main(String[] args) { List<String> list=new ArrayList<String> ...

  10. C++ 和Java继承机制的比较

    摘要: C++支持类的多继承,而Java采用类的单继承.C++中的继承成分只有类(模板属于带参数的类,结构和联合是特殊的类),Java中除了类还有接口的继承,而且允许接口的多继承,可以间接地实现类多继 ...