博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
E - A Trivial Problem(求满足x!的尾数恰好有m个0的所有x)
阅读量:4599 次
发布时间:2019-06-09

本文共 2020 字,大约阅读时间需要 6 分钟。

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。做法:暴力打表找规律,代码如下:

1 import java.math.BigInteger; 2 public class Main{ 3     public static void main(String[] args) { 4         for(int i=1;i<=100;++i){ 5             BigInteger a=new BigInteger("1"); 6             for(int j=1;j<=i;++j){ 7                  BigInteger num = new BigInteger(String.valueOf(j));     8                  a=a.multiply(num);// 调用自乘方法 9             }10             System.out.println(i+" "+a);11         }    12     }13 }

 通过打表可以发现:当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代码:

1 #include
2 using namespace std; 3 int main(){ 4 int n=0,t=5,m,tmp;bool flag=false; 5 cin>>m; 6 while(n<=m){ 7 tmp=t; 8 while(tmp%5==0){n++;tmp/=5;}//n表示的个数,累加因子5的个数 9 if(n==m){10 puts("5");11 for(int i=0;i<5;i++)12 cout<
<<(i==4?"\n":" ");13 flag=true;break;14 }15 t+=5;16 }17 if(!flag)puts("0");18 return 0;19 }

 

转载于:https://www.cnblogs.com/acgoto/p/9196949.html

你可能感兴趣的文章
使用JavaScriptSerializer序列化集合、字典、数组、DataTable为JSON字符串 ...
查看>>
20个Flutter实例视频教程-第12节: 流式布局 模拟添加照片效果
查看>>
阶段1 语言基础+高级_1-3-Java语言高级_02-继承与多态_第1节 继承_1_继承的概述
查看>>
用户场景分析
查看>>
hdoj1002
查看>>
数据结构,你还记得吗(中)
查看>>
C#规范整理·资源管理和序列化
查看>>
java IO笔记(InputStream/OutputSteram)
查看>>
Android_AsyncTask
查看>>
软件项目版本号的命名规则及格式
查看>>
排序算法
查看>>
屏幕滑动与滚动条事件进行绑定
查看>>
js清除浏览器缓存的几种方法
查看>>
hdu 3127(矩阵切割)
查看>>
hdu 1864(01背包)
查看>>
[stl] SGI STL的空间配置器
查看>>
【IIS】IIS中同时满足集成模式和经典模式
查看>>
使用DOM解析XML文档
查看>>
python函数参数传递总结
查看>>
java生成Https证书,及证书导入的步骤和过程
查看>>