Manthan, Codefest 16(B--A Trivial Problem)
2 seconds
256 megabytes
standard input
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?
The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial.
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.
1
5
5 6 7 8 9
5
0
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)的更多相关文章
- Manthan, Codefest 16 B. A Trivial Problem 二分 数学
B. A Trivial Problem 题目连接: http://www.codeforces.com/contest/633/problem/B Description Mr. Santa ask ...
- CF Manthan, Codefest 16 B. A Trivial Problem
数学技巧真有趣,看出规律就很简单了 wa 题意:给出数k 输出所有阶乘尾数有k个0的数 这题来来回回看了两三遍, 想的方法总觉得会T 后来想想 阶乘 emmm 1*2*3*4*5*6*7*8*9 ...
- Manthan, Codefest 16
暴力 A - Ebony and Ivory import java.util.*; import java.io.*; public class Main { public static void ...
- Manthan, Codefest 16 B 数学
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CF Manthan, Codefest 16 G. Yash And Trees 线段树+bitset
题目链接:http://codeforces.com/problemset/problem/633/G 大意是一棵树两种操作,第一种是某一节点子树所有值+v,第二种问子树中节点模m出现了多少种m以内的 ...
- CF #Manthan, Codefest 16 C. Spy Syndrome 2 Trie
题目链接:http://codeforces.com/problemset/problem/633/C 大意就是给个字典和一个字符串,求一个用字典中的单词恰好构成字符串的匹配. 比赛的时候是用AC自动 ...
- Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵
H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...
- Manthan, Codefest 16 E. Startup Funding ST表 二分 数学
E. Startup Funding 题目连接: http://codeforces.com/contest/633/problem/E Description An e-commerce start ...
- 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 ...
随机推荐
- UI第十七节——UIScrollView
// 实例化一个ScrollView UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen main ...
- 给div添加滚动条
最简单的方法: <div style="height:300px;width:100px;overflow:auto"><div/>(height和widt ...
- JS 初级(三)接上
传送门 http://www.cnblogs.com/Sabo-dudu/p/5788197.html 现阶段我就了解了这么多,在以后的学习中,我会不断的更新,如果有什么不同的见解可以一块学习,谁有更 ...
- 【新手出发】从搭虚拟机开始,一步一步在CentOS上跑起来.Net Core程序
文章背景 微软6月26号发布core 1.0版本后,园子里关于这方面的文章就更加火爆了,不管是从文章数量还是大家互动的热情来看,绝对是最热门的技术NO.1.我从去年底开始接触.net core到现在也 ...
- mysql的enum和set数据类型
定义一个ENUM或者SET类型,可以约束存入的数值. ENUM中的值必须是定义过数值列中的一个,比如ENUM('a','b','c'),存入的只能是'a'或者'b'或者'c',如果存入'','d'或者 ...
- Java中关于String类型的10个问题
1. 如何比较两个字符串?用“=”还是equals 简单来说,“==”是用来检测俩引用是不是指向内存中的同一个对象,而equals()方法则检测的是两个对象的值是否相等.只要你想检测俩字符串是不是相等 ...
- Tomcat的设定
tomcat 版本 apache-tomcat-7.0.68-windows-x64 1.解压文件到 eclipse文件夹中,这个放哪都可以,个人习惯而已 2.tomcat目录结构 图片为盗图- 3 ...
- erlang 虚机性能调优
erlang 默认启动参数更多的是针对电信平台实时特性,简单调整参数能很大程度降低CPU消耗,提高处理能力. 1. 关闭spin_wait 设置参数:+sbwt none 我上一篇文章提到:erlan ...
- JSP复习整理(五)JavaBean生命周期
一.创建一个JavaBean UserBean.java package jsp.test; public class UserBean { private String userName; priv ...
- C# Stream
转载:C# 温故而知新:Stream篇(一.二) http://www.cnblogs.com/JimmyZheng/archive/2012/03/17/2402814.html#no2 http: ...