Problem description

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.

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.

解题思路:题目的意思就是要输出自然数x!的尾数刚好有m个0的所有x。做法:暴力打表找规律,代码如下:

 import java.math.BigInteger;
public class Main{
public static void main(String[] args) {
for(int i=1;i<=100;++i){
BigInteger a=new BigInteger("1");
for(int j=1;j<=i;++j){
BigInteger num = new BigInteger(String.valueOf(j));
a=a.multiply(num);// 调用自乘方法
}
System.out.println(i+" "+a);
}
}
}

通过打表可以发现:当m=1时,x∈[5,9];(共有5个元素)

当m=2时,x∈[10,14];(共有5个元素)

当m=3时,x∈[15,19];(共有5个元素)

当m=4时,x∈[20,24];(共有5个元素)

当m=5时,无x;

当m=6时,x∈[25,29];(共有5个元素)

......

因此,我们只需对5的倍数进行枚举,只要位数n<=m,则当n==m时,必有5个元素满足条件,否则输出"0"。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
int main(){
int n=,t=,m,tmp;bool flag=false;
cin>>m;
while(n<=m){
tmp=t;
while(tmp%==){n++;tmp/=;}//n表示的个数,累加因子5的个数
if(n==m){
puts("");
for(int i=;i<;i++)
cout<<t+i<<(i==?"\n":" ");
flag=true;break;
}
t+=;
}
if(!flag)puts("");
return ;
}

E - A Trivial Problem(求满足x!的尾数恰好有m个0的所有x)的更多相关文章

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

  2. Codeforces 633B A Trivial Problem

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

  3. cf 633B A trivial problem

    Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an i ...

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

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

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

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

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

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

  7. E - An Awful Problem 求两段时间内满足条件的天数//lxm

    In order to encourage Hiqivenfin to study math, his mother gave him a sweet candy when the day of th ...

  8. 洛谷 P1865 A % B Problem(求区间质数个数)

    题目背景 题目名称是吸引你点进来的 实际上该题还是很水的 题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对 ...

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

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

随机推荐

  1. js for 循环 添加tr td 算法

    StringBuffer sb=new StringBuffer(); int n = 5; sb.append("<tr>"); List<MenuBean&g ...

  2. [luogu2154 SDOI2009] 虔诚的墓主人(树状数组+组合数)

    传送门 Solution 显然每个点的权值可以由当前点上下左右的树的数量用组合数\(O(1)\)求出,但这样枚举会T 那么我们考虑一段连续区间,对于一行中两个常青树中间的部分左右树的数量一定,我们可用 ...

  3. case....when ...多重判断

    CASE...WHEN 进行多重判断 CASE WHEN A  IS NOT NULL THEN B WHEN C IS NULL THEN CASE WHEN D IS NOT NULL THEN ...

  4. 14.multi_match+most-fields策略

    主要知识点 most-fields策略的用法 most-fields策略和best-fields的比较         best-fields策略:将某一个field匹配尽可能多的关键词的doc优先返 ...

  5. BFOA

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> ...

  6. 调用ms自带的合成语音TTS

    通过import of Component导入封装TTS引擎,然后选择: 最后调用: MyVoce := CoSpVoice.Create; MyVoce.Pause;//暂停 MyVoce.Stat ...

  7. 【codeforces 797C】Minimal string

    [题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...

  8. SCU Travel

    Travel The country frog lives in has n towns which are conveniently numbered by 1,2,…,n . Among n(n− ...

  9. mysql5.7 简易修改mysql密码

    MySQL 5.7 mysql库的user表中已经不再有password字段,取而代之的为authentication_string修改语法相同,步骤也相同.注意:/etc/my.cnf这个配置文件中 ...

  10. 深入分析Linux自旋锁

    原创 2016-08-12 tekkamanninja CU技术社区   作者| tekkamanninja本文版权由tekkamanninja所有,如需转载,请联系本公众号获取授权!在复习休眠的过程 ...