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;
};
}

  

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. Windows 安装JRuby 生成 war 到 tomcat 运行

    Windows安装JRuby Rails 直接下载 JRuby,不装 Ruby. http://jruby.org/download 该安装包可以配好环境变量 %JRUBY_HOME% 等 安装 bu ...

  2. CentOS 6.5 安装 Redis-3.2.6

    到官网下载最新版的 Redis-3.2.6, 我把它放到文件夹:/usr/local/src/centos-sdk/source2/redis 安装脚本 redis-3.2.6.sh #!/bin/b ...

  3. C和指针 第十五章 二进制I/O

    二进制I/O 数据写入到文件效率最高的是用二进制形式写入,二进制输出避免了在数值转换为字符串过程中,所涉及的开销和精度损失,但而精致并非人眼所能阅读,所以这个技巧只有当数据被另一个程序按顺序读取才能使 ...

  4. libvirt 网络手册(一)

    如果选择网络类型 在一个专用的服务器上,虚拟机常常需要被从公网访问(也就是每个虚拟机都需要公网地址),这时就需要桥接网络,它使得每个虚拟机有自己的IPV4和IPV6地址.如果桥接不可用,可以创建一个R ...

  5. JS 深浅拷贝

    首先理解概念 浅拷贝: 只复制对象的基本类型, 对象类型, 仍属于原来的引用. 深拷贝: 不紧复制对象的基本类, 同时也复制原对象中的对象.就是说完全是新对象产生的. 首先看浅拷贝 //浅拷贝 var ...

  6. WinForm用户控件、动态创建添加控件、timer控件--2016年12月12日

    好文要顶 关注我 收藏该文 徐淳 关注 - 1 粉丝 - 3       0 0     用户控件: 通过布局将多个控件整合为一个控件,根据自己的需要进行修改,可对用户控件内的所有控件及控件属性进行修 ...

  7. toast组件小结

    简介:toast是"吐司"的意思,它属于android杂项组件,是一个简单的消息提示框,类似于javascript中的alert. 作用 显示文本 显示图片 显示图文 3.常用方法 ...

  8. iOS SpriteKit 问题

    今天偶然发现 向SKShapeNode添加子 node时,子node参考的是 SKShapeNode的parent的坐标系,但是如果使用SKSpriteNode却是使用自己的坐标系,带研究.而且sha ...

  9. OnlineTV 电视播放工具

    通过网络使用电脑收看电视节目的播放工具,跟其他播放软件不同的是增加了录制功能. getList_bin_src.7z 获取电视直播源 OnlineTV-20161005.tar.xz OnlineTV ...

  10. How to Fix GNOME License Not Accepted Issue on CentOS 7

    This post assume that you have just finished the Gnome GUI installation on CentOS 7 by using “yum gr ...