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. Ansible 利用playbook批量部署mariadb

    环境说一下 192.168.30.21     ansible 192.168.30.25     client1 192.168.30.26     client2 这里我的ansible环境已经部 ...

  2. Error from server at http://127.0.0.1:8983/solr/xxx: undefined field type

    undefined field type就是说没有定义type类型,这样情况下,可以新建一个带type的索引,比如:{type:1, id:1, name:"张三"}

  3. 1.scrapy爬取的数据保存到es中

    先建立es的mapping,也就是建立在es中建立一个空的Index,代码如下:执行后就会在es建lagou 这个index.     from datetime import datetime fr ...

  4. GlobalSign 域名型 SSL 证书

      GlobalSign 域名型 SSL 证书,支持通配符型,只验证域名所有权,属于DV 域名验证级SSL证书,无须递交书面审查资料,网上申请便捷有效率.提供40位/56位/128位,最高256位自适 ...

  5. iOS学习笔记17-FMDB你好!

    上一节我已经介绍了SQLite的简单使用,不了解的可以提前去看一下iOS学习笔记16-数据库SQLite,这节我们来讲下FMDB. 一.FMDB介绍 FMDB是一种第三方的开源库,FMDB就是对SQL ...

  6. 清北学堂模拟赛d3t4 a

    分析:很水的一道题,就是用栈来看看是不是匹配就好了,只是最后没有判断栈是否为空而WA了一个点,以后做题要注意了. #include <bits/stdc++.h> using namesp ...

  7. [bzoj3529][Sdoi2014]数表_树状数组_莫比乌斯反演

    数表 bzoj-3529 Sdoi-2014 题目大意:n*m的数表,第i行第j列的数是同时整除i和j的所有自然数之和.给定a,求数表中所有不超过a的和. 注释:$1\le n,m \le 10^5$ ...

  8. 洛谷—— P1092 虫食算

    https://www.luogu.org/problem/show?pid=1092 题目描述 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母.来看一个简 ...

  9. 2015 Changchun Regional

    弱没机会去长春,但拿了题来做了,加上请教各路大牛,理论AC了一发,但没实现~(感谢各路有形无形的大牛的指导) A题~Too Rich 给你1,5,10,20,50,100,200,500,1000,2 ...

  10. Android面试准备 第一天 第2-4例

    參考:http://blog.csdn.net/lmj623565791/article/details/24015867. .假设有个100M大的文件.须要上传至server中.而serverfor ...