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 ...
随机推荐
- HTML <input type="file">上传文件——结合asp.net的一个文件上传示例
HTML的代码:(关键是要在form里设置enctype="multipart/form-data",这样才能在提交表单时,将文件以二进制流的形式传输到服务器) 一. <fo ...
- js 中histroy.back()与history.go()的区别
样例: js6.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...
- word20161224
V.34 V.90 validation / 验证 value entry / 值项 variable / 变量 variable bit rate, VBR / 可变传输率 VBR, variabl ...
- 一些VS2013下使用QT和MFC的错误解决方案
http://blog.csdn.net/lovejiayang/article/details/51853191
- CDR VBA将字母改为大写
ActiveShape.Text.FontProperties.Uppercase = cdrSmallCapsFontCase
- Reverse Core 第三部分 - 21章 - Windows消息钩取
@author: dlive @date: 2016/12/19 0x01 SetWindowsHookEx() HHOOK SetWindowsHookEx( int idHook, //hook ...
- php给客户端返回数据注意。
亲身测试: 返回的时候不要直接返回字符串,要用数组的方式返回数据客户端才能接收. 看代码. <?php require_once("../base.php"); functi ...
- UILabel 根据文本内容设置frame
CGRect senderFrame = cell.senderLabel.frame; CGRect creatAtFrame = cell.creatAtLabel.frame; CG ...
- 牛顿方法(Newton's Method)
在讲义<线性回归.梯度下降>和<逻辑回归>中我们提到可以用梯度下降或梯度上升的方式求解θ.在本文中将讲解另一种求解θ的方法:牛顿方法(Newton's method). 牛顿方 ...
- Blender 脚本之 Operator 初探
addon(插件)用来扩展 Blender 的功能,跟其他软件里的 plugin(插件)一样,去掉不会影响软件的运行.插件可以加到 Blender 的用户偏好设置目录里,或者就在你所编辑的.blend ...