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. 单实例redis分布式锁的简单实现

    redis分布式锁的基本功能包括, 同一刻只能有一个人占有锁, 当锁被其他人占用时, 获取者可以等待他人释放锁, 此外锁本身必须能超时自动释放. 直接上java代码, 如下: package com. ...

  2. HDU-4055 Number String 动态规划 巧妙的转移

    题目链接:https://cn.vjudge.net/problem/HDU-4055 题意 给一个序列相邻元素各个上升下降情况('I'上升'D'下降'?'随便),问有几种满足的排列. 例:ID 答: ...

  3. POJ1161——The Suspects

    POJ1161——The Suspects   The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 48 ...

  4. HTML学习笔记之HTML5新特性

    目录 1.拖放 2.画布 3.可伸缩矢量图形 4.地理定位 5.Web 存储 6.应用缓存 7.Web Worker 1.拖放 拖放是一种常见的特性,用于抓取对象以后拖到另一个位置,它是 HTML5 ...

  5. axios请求中跨域及post请求问题解决方案

    闲话不多说,用到vue的童鞋们应该大部分都会遇到请求中的各种奇葩问题,昨天研究一天,终于搞出来个所以然了,写篇文章拯救一下广大的童鞋们,某度娘当然也可以搜到,但一般解决了一个问题后就会出现另外一个问题 ...

  6. STM32学习笔记:读写内部Flash(介绍+附代码)

    一.介绍 首先我们需要了解一个内存映射: stm32的flash地址起始于0x0800 0000,结束地址是0x0800 0000加上芯片实际的flash大小,不同的芯片flash大小不同. RAM起 ...

  7. hdu 5182 PM2.5

    问题描述 目前,我们用PM2.5的含量来描述空气质量的好坏.一个城市的PM2.5含量越低,它的空气质量就越好.所以我们经常按照PM2.5的含量从小到大对城市排序.一些时候某个城市的排名可能上升,但是他 ...

  8. 如何在Tomcat (6/7/8.0) 安装SSL证书

    第一步:进入Tomcat安装目录,把证书的jks格式文件放在tomcat安装目录的conf目录下即可. conf/ssl/371cloud.cn.jks 第二步: 打开tomcat配置文件 conf/ ...

  9. [TYVJ1730]二逼平衡树

    [TYVJ1730]二逼平衡树 题目 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查 ...

  10. hdu_hpu第八次周赛_1001 To and Fro 201310270918

    To and Fro Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Su ...