E - A Trivial Problem(求满足x!的尾数恰好有m个0的所有x)
Problem description
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 of n 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 mzeroes. 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 is n! = 1·2·3·...·n.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
解题思路:题目的意思就是要输出自然数x!的尾数刚好有m个0的所有x。做法:暴力打表找规律,代码如下:
import java.math.BigInteger;
public class Main{
public static void main(String[] args) {
for(int i=1;i<=100;++i){
BigInteger a=new BigInteger("1");
for(int j=1;j<=i;++j){
BigInteger num = new BigInteger(String.valueOf(j));
a=a.multiply(num);// 调用自乘方法
}
System.out.println(i+" "+a);
}
}
}
通过打表可以发现:当m=1时,x∈[5,9];(共有5个元素)
当m=2时,x∈[10,14];(共有5个元素)
当m=3时,x∈[15,19];(共有5个元素)
当m=4时,x∈[20,24];(共有5个元素)
当m=5时,无x;
当m=6时,x∈[25,29];(共有5个元素)
......
因此,我们只需对5的倍数进行枚举,只要位数n<=m,则当n==m时,必有5个元素满足条件,否则输出"0"。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n=,t=,m,tmp;bool flag=false;
cin>>m;
while(n<=m){
tmp=t;
while(tmp%==){n++;tmp/=;}//n表示的个数,累加因子5的个数
if(n==m){
puts("");
for(int i=;i<;i++)
cout<<t+i<<(i==?"\n":" ");
flag=true;break;
}
t+=;
}
if(!flag)puts("");
return ;
}
E - A Trivial Problem(求满足x!的尾数恰好有m个0的所有x)的更多相关文章
- Manthan, Codefest 16(B--A Trivial Problem)
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 633B A Trivial Problem
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- cf 633B A trivial problem
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an i ...
- Manthan, Codefest 16 B. A Trivial Problem 二分 数学
B. A Trivial Problem 题目连接: http://www.codeforces.com/contest/633/problem/B Description Mr. Santa ask ...
- codeforces 633B B. A Trivial Problem(数论)
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CodeForces - 633B A Trivial Problem 数论-阶乘后缀0
A Trivial Problem Mr. Santa asks all the great programmers of the world to solve a trivial problem. ...
- E - An Awful Problem 求两段时间内满足条件的天数//lxm
In order to encourage Hiqivenfin to study math, his mother gave him a sweet candy when the day of th ...
- 洛谷 P1865 A % B Problem(求区间质数个数)
题目背景 题目名称是吸引你点进来的 实际上该题还是很水的 题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对 ...
- CF Manthan, Codefest 16 B. A Trivial Problem
数学技巧真有趣,看出规律就很简单了 wa 题意:给出数k 输出所有阶乘尾数有k个0的数 这题来来回回看了两三遍, 想的方法总觉得会T 后来想想 阶乘 emmm 1*2*3*4*5*6*7*8*9 ...
随机推荐
- EAS之校验检查
先了解一下权限接口类提供的有关权限项检查的方法public boolean hasFunctionPermission(IObjectPK userPK,IObjectPK orgPK,String ...
- 浅谈 extern "C"
今天上课实在无聊,就看了看 extern "C" 的作用,看了以后对它有了一点点理解,在这里给大家分享一下(本菜鸡水平有限,如若有说得不对的地方,还望大家指出). extern 关 ...
- Codeforces Round #467 Div.2题解
A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Linux文件、目录属性
文件.目录属性 可能有人觉得,文件这东西这么普通有什么好讲的,,,其实不然,在linux中一切皆文件,搞清楚文件的本质,将对我们大有裨益. 文件.目录属性简介 举个例子 randolf@localho ...
- bytes类型和python中编码的转换方法
一.bytes类型 bytes类型是指一堆字节的集合,在python中以b开头的字符串都是bytes类型.例如: >>> a = "中国" >>> ...
- 第一节:web爬虫之requests
Requests库是用Python编写的,并且Requests是一个优雅而简单的Python HTTP库,在使用Requests库时更加方便,可以节约我们大量的工作,完全满足HTTP测试需求.
- seminar information (Email template)
The following is an email example of seminar information **************** Dear all, It is a plea ...
- 关于read和fread
1.fread与read的区别---open和fopen的区别--fread函数和fwrite函数:http://blog.csdn.net/dreamtdp/article/details/7560 ...
- 在 ServiceModel 客户端配置部分中,找不到引用协定“XXX”的默认终结点元素
一.问题 在调用远程web services接口时出现了以下问题: 二.可能的原因和解决方法 网站根目录里的web.config文件缺少了相应的配置信息 <?xml version=" ...
- scrapy——7 scrapy-redis分布式爬虫,用药助手实战,Boss直聘实战,阿布云代理设置
scrapy——7 什么是scrapy-redis 怎么安装scrapy-redis scrapy-redis常用配置文件 scrapy-redis键名介绍 实战-利用scrapy-redis分布式爬 ...