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 ...
随机推荐
- STL~heap
1.定义 堆:若将此序列所存储的向量R[1..n]看做是一棵完全二叉树的存储结构,则堆实质上是满足如下性质的完全二叉树 树中任一非叶子结点的关键字均不大于(或不小于)其子结点的关键字.分为大根数(默认 ...
- OSI7层模型详解
首先我们借用百度百科上的图片来基本了解一下OSI7层模型的名称以及结构.下面我将从最底层一层一层往上介绍. 物理层:基于Bit传输,是属于物理信道,最基本的机械.电子.定时接口通信信道. 数据链路层: ...
- Jquery 轮播图简易框架
=====================基本结构===================== <div class="carousel" style="width: ...
- qt添加cef库嵌入web [转]
qt cef嵌入web 原文http://blog.sina.com.cn/s/blog_9e59cf590102vnfc.html 最近项目需要,研究了下libcef库. Cef(Chromium ...
- 【日记】thinkphp项目阿里云ECS服务器部署
项目本地开发告一段落.准备上传到服务器上测试 技术组成 thinkphp+mysql+阿里ECS 代码管理方式git 一.阿里ECS服务器配置 1.因为线上已经有几个站点了.所以要配置ngnix多站 ...
- dubbo升级spring4与cxf
阿里的dubbo项目是基于spring2.x的.但之后停止更新了.当当网有根据dubbo扩展成dubbox,基于spring3.x,但我的项目中用的是spring4.x,于是fork了dubbox,自 ...
- php阳历转农历的类 谷歌到的
<?phpclass Lunar { var $MIN_YEAR = 1891; var $MAX_YEAR = 2100; var $lunarInfo = array( ...
- 为RecyclerView的不同item项实现不同的布局(添加分类Header)
最近在做一个应用的时候,需要为GridLayoutManager添加头部header,然后自然而然就想到了用不同的itemType去加载不同的布局. 1.实现多item布局,用不同的itemType去 ...
- Redis的Python实践,以及四中常用应用场景详解——学习董伟明老师的《Python Web开发实践》
首先,简单介绍:Redis是一个基于内存的键值对存储系统,常用作数据库.缓存和消息代理. 支持:字符串,字典,列表,集合,有序集合,位图(bitmaps),地理位置,HyperLogLog等多种数据结 ...
- width:100%;与width:auto;的区别
<div> <p>1111</p> </div> div{ width:980px; background-color: #ccc; height:30 ...