B. A Trivial Problem
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ofn 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 m zeroes. 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 isn! = 1·2·3·...·n.

In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.

题目纠结时间有点长。。

package ManthanCodefest16;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Scanner; /**
* Created by lenovo on 2016-03-02.
*/
public class B {
public static void main(String[] args){
Scanner scanner = new Scanner(new InputStreamReader(System.in));
/*
* 这道题目是数一个数中能被 5 整除的次数,然后每次都能找到这个序列末尾的数,而且除了第一组
* 其他的都是5个数字一组。恩,就这样
* */
int m;
int[] arr = new int[100000 + 100];
arr[0] = 4;
arr[1] = 9;
int num = 1;
for(int i = 2; i < arr.length;){
arr[i] = arr[i-num] + 5;
num = num(arr[i]+1);
i += num;
}
while(scanner.hasNext()){
m = scanner.nextInt();
if(arr[m] == 0){
System.out.println(0);
} else {
if(arr[m] == 4){
System.out.println(4);
for(int i = 1; i <= arr[m]; ++i){
System.out.print(i+" ");
}
} else {
System.out.println(5);
for(int i = arr[m]-5; i <= arr[m]; ++i){
System.out.println(i+" ");
}
}
}
}
} public static int num(int n){
int cnt = 0;
while(n % 5 == 0 && n != 0){
n /= 5;
cnt++;
}
return cnt;
};
}

  

最新文章

  1. 用户反馈:对 Rafy 开发框架的一些个人建议
  2. windos系统定时执行批处理文件(bat文件)
  3. GPU渲染和GDI
  4. DIV横排/竖排滚动(white-space/::-webkit-scrollbar的使用技巧以及display: inline-block的选择)支持手势
  5. jQuery.Callbacks 源码解读二
  6. javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint
  7. C# 制作 仪表
  8. http://www.cutt.com/
  9. 处理Oracle数据中的无效对象
  10. E:I Think I Need a Houseboat-poj
  11. poj2449 (第k条最短路)
  12. Mac本地搭建kubernetes环境
  13. C# 应用Excel条件格式(一)
  14. PHP 生成器语法
  15. safari无法调试iphone提示“无可检查的应用程序”的解决方法
  16. Nginx、HAProxy、LVS三者的优缺点
  17. C++ 提取网页内容系列之三
  18. [转帖]ARM 相关内容
  19. 线性代数 | Linear Algebra
  20. Oracle12c中容错&amp;amp;性能新特性之表空间组

热门文章

  1. Netty 实现 WebSocket 聊天功能
  2. synchronized使用说明
  3. git用法之[回滚代码]
  4. python , angular js 学习记录【3】
  5. BZOJ 1236: SPOJ1433 KPSUM
  6. java中面向对象的一些知识(一)
  7. 移动端H5页面高清多屏适配方案
  8. mysqldump和xtrabackup备份原理实现说明
  9. struts2笔记
  10. Python初学者应了解的技巧