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. 1
output
  1. 5
    5 6 7 8 9
input
  1. 5
output
  1. 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.

题目纠结时间有点长。。

  1. package ManthanCodefest16;
  2. import java.io.InputStreamReader;
  3. import java.math.BigInteger;
  4. import java.util.Scanner;
  5.  
  6. /**
  7. * Created by lenovo on 2016-03-02.
  8. */
  9. public class B {
  10. public static void main(String[] args){
  11. Scanner scanner = new Scanner(new InputStreamReader(System.in));
  12. /*
  13. * 这道题目是数一个数中能被 5 整除的次数,然后每次都能找到这个序列末尾的数,而且除了第一组
  14. * 其他的都是5个数字一组。恩,就这样
  15. * */
  16. int m;
  17. int[] arr = new int[100000 + 100];
  18. arr[0] = 4;
  19. arr[1] = 9;
  20. int num = 1;
  21. for(int i = 2; i < arr.length;){
  22. arr[i] = arr[i-num] + 5;
  23. num = num(arr[i]+1);
  24. i += num;
  25. }
  26. while(scanner.hasNext()){
  27. m = scanner.nextInt();
  28. if(arr[m] == 0){
  29. System.out.println(0);
  30. } else {
  31. if(arr[m] == 4){
  32. System.out.println(4);
  33. for(int i = 1; i <= arr[m]; ++i){
  34. System.out.print(i+" ");
  35. }
  36. } else {
  37. System.out.println(5);
  38. for(int i = arr[m]-5; i <= arr[m]; ++i){
  39. System.out.println(i+" ");
  40. }
  41. }
  42. }
  43. }
  44. }
  45.  
  46. public static int num(int n){
  47. int cnt = 0;
  48. while(n % 5 == 0 && n != 0){
  49. n /= 5;
  50. cnt++;
  51. }
  52. return cnt;
  53. };
  54. }

  

Manthan, Codefest 16(B--A Trivial Problem)的更多相关文章

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

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

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

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

  3. Manthan, Codefest 16

    暴力 A - Ebony and Ivory import java.util.*; import java.io.*; public class Main { public static void ...

  4. Manthan, Codefest 16 B 数学

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

  5. CF Manthan, Codefest 16 G. Yash And Trees 线段树+bitset

    题目链接:http://codeforces.com/problemset/problem/633/G 大意是一棵树两种操作,第一种是某一节点子树所有值+v,第二种问子树中节点模m出现了多少种m以内的 ...

  6. CF #Manthan, Codefest 16 C. Spy Syndrome 2 Trie

    题目链接:http://codeforces.com/problemset/problem/633/C 大意就是给个字典和一个字符串,求一个用字典中的单词恰好构成字符串的匹配. 比赛的时候是用AC自动 ...

  7. Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵

    H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...

  8. Manthan, Codefest 16 E. Startup Funding ST表 二分 数学

    E. Startup Funding 题目连接: http://codeforces.com/contest/633/problem/E Description An e-commerce start ...

  9. Manthan, Codefest 16 G. Yash And Trees dfs序+线段树+bitset

    G. Yash And Trees 题目连接: http://www.codeforces.com/contest/633/problem/G Description Yash loves playi ...

随机推荐

  1. STL~heap

    1.定义 堆:若将此序列所存储的向量R[1..n]看做是一棵完全二叉树的存储结构,则堆实质上是满足如下性质的完全二叉树 树中任一非叶子结点的关键字均不大于(或不小于)其子结点的关键字.分为大根数(默认 ...

  2. OSI7层模型详解

    首先我们借用百度百科上的图片来基本了解一下OSI7层模型的名称以及结构.下面我将从最底层一层一层往上介绍. 物理层:基于Bit传输,是属于物理信道,最基本的机械.电子.定时接口通信信道. 数据链路层: ...

  3. Jquery 轮播图简易框架

    =====================基本结构===================== <div class="carousel" style="width: ...

  4. qt添加cef库嵌入web [转]

    qt cef嵌入web 原文http://blog.sina.com.cn/s/blog_9e59cf590102vnfc.html 最近项目需要,研究了下libcef库. Cef(Chromium ...

  5. 【日记】thinkphp项目阿里云ECS服务器部署

    项目本地开发告一段落.准备上传到服务器上测试 技术组成 thinkphp+mysql+阿里ECS  代码管理方式git 一.阿里ECS服务器配置 1.因为线上已经有几个站点了.所以要配置ngnix多站 ...

  6. dubbo升级spring4与cxf

    阿里的dubbo项目是基于spring2.x的.但之后停止更新了.当当网有根据dubbo扩展成dubbox,基于spring3.x,但我的项目中用的是spring4.x,于是fork了dubbox,自 ...

  7. php阳历转农历的类 谷歌到的

    <?phpclass Lunar {    var $MIN_YEAR = 1891;    var $MAX_YEAR = 2100;    var $lunarInfo = array(   ...

  8. 为RecyclerView的不同item项实现不同的布局(添加分类Header)

    最近在做一个应用的时候,需要为GridLayoutManager添加头部header,然后自然而然就想到了用不同的itemType去加载不同的布局. 1.实现多item布局,用不同的itemType去 ...

  9. Redis的Python实践,以及四中常用应用场景详解——学习董伟明老师的《Python Web开发实践》

    首先,简单介绍:Redis是一个基于内存的键值对存储系统,常用作数据库.缓存和消息代理. 支持:字符串,字典,列表,集合,有序集合,位图(bitmaps),地理位置,HyperLogLog等多种数据结 ...

  10. width:100%;与width:auto;的区别

    <div> <p>1111</p> </div> div{ width:980px; background-color: #ccc; height:30 ...