cf 633B A trivial problem
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?
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 mzeroes. 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 is n! = 1·2·3·...·n.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=0x3f3f3f3f;
const int maxn=500100; int m,cnt;
int num[maxn],a[maxn];
int fun(int n)
{
int ans=0;
while(n)
{
n/=5;
ans+=n;
}
return ans;
} int main()
{
for(int i=0; i<maxn; i++)
a[i]=fun(i);
while(~scanf("%d",&m))
{
cnt=0;
int i;
for(i=0; i<maxn; i++)
{
if(a[i]==m)
{
num[cnt++]=i;
}
}
printf("%d\n",cnt);
if(cnt)
{
for(i=0; i<cnt; i++)
{
if(i) printf(" ");
printf("%d",num[i]);
}
printf("\n");
}
}
return 0;
} #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int MAXN = 1e9; int fun(int n)
{
int cnt = 0;
while(n)
{
n/=5;
cnt+=n;
}
return cnt;
}
int Two(int l, int r, int m)
{
int ans = 0;
while(r >= l)
{
int mid = (l + r) >> 1;
int res = fun(mid);
if(res < m)
l = mid + 1;
else if(res >= m)
{
r = mid - 1;
ans = mid;
}
}
return ans;
}
int main()
{
int m;
while(cin >> m)
{
int l = 1, r = MAXN;
int L = Two(l, r, m), R = Two(l, r, m+1);
if(L == 0 || fun(R-1) != m) cout << 0 << endl;
else
{
cout << R - L << endl;
for(int i = L; i <= R-1; i++)
{
if(i > L) cout << " ";
cout << i;
}
cout << endl;
}
}
return 0;
}
cf 633B A trivial problem的更多相关文章
- Codeforces 633B 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. ...
- codeforces 633B B. A Trivial Problem(数论)
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 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 ...
- 把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend
//把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend //dp[i][j]:把第i个数转成第j小的数,最小花费 //此题与po ...
- Manthan, Codefest 16 B. A Trivial Problem 二分 数学
B. A Trivial Problem 题目连接: http://www.codeforces.com/contest/633/problem/B Description Mr. Santa ask ...
- 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 ...
- CF Manthan, Codefest 16 B. A Trivial Problem
数学技巧真有趣,看出规律就很简单了 wa 题意:给出数k 输出所有阶乘尾数有k个0的数 这题来来回回看了两三遍, 想的方法总觉得会T 后来想想 阶乘 emmm 1*2*3*4*5*6*7*8*9 ...
- 【dp/贪心】CF 780 (Div. 3), problem: (C) Get an Even String
Problem - C - Codeforces 难度: 1300 input 6 aabbdabdccc zyx aaababbb aabbcc oaoaaaoo bmefbmuyw output ...
随机推荐
- 2016-2017-2 20155117实验二《Java面向对象程序设计》实验报告
实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验要求 1.参考Intellj IDEA 简易教程 提交 ...
- laravel 模糊查询
模糊查询: Model::where('field_name','like','%'.$keywords.'%')->get() 转载:http://wenda.golaravel.com/qu ...
- php sprintf格式化注入
URL:http://efa4e2c2b8df4ce69454639f4e3727071652c31167f341a4.game.ichunqiu.com/ 简单的说就是sprintf中%1$\'会将 ...
- python进阶之py文件内置属性
前言 对于任何一个python文件来说,当python解释器运行一个py文件,会自动将一些内容加载到内置的属性中:一个模块我们可以看做是一个比类更大的对象. 查看模块的内置属性 我们先创建一个典型的p ...
- Linux进程调度原理【转】
转自:http://www.cnblogs.com/zhaoyl/archive/2012/09/04/2671156.html Linux进程调度的目标 1.高效性:高效意味着在相同的时间下要完成更 ...
- Battery Charging Specification 1.2 中文详解 来源:www.chengxuyuans.com
1. Introduction 1.1 Scope 规范定义了设备通过USB端口充电的检测.控制和报告机制,这些机制是USB2.0规范的扩展,用于专用 充电器(DCP).主机(SDP).hub(SDP ...
- linux常用函数简单介绍
mmap函数简介: mmap函数是unix/linux下的系统调用,来看<Unix Netword programming>卷二12.2节对mmap的介绍: The mmap functi ...
- Firefox缓存文件夹位置设置及清除缓存方法
地址栏敲入: about:config, 新建一个"browser.cache.disk.parent_directory", 并设置为你要的缓存文件夹, 例如: "F ...
- JavaScript 去字符串空格
JavaScript 去字符串空格 (利用正则) # str为要去除空格的字符串: # 去除所有空格: str = str.replace(/\s+/g,""); # 去除两头空格 ...
- Unity 软件使用事项
打开旧版工程 目前发现两种方式来触发升级程序: 1.Unity软件启动时选择旧版工程,触发更新 2.直接打开旧版工程的场景文件,触发更新 在使用中发现一种错误做法,不知道是不是共性问题,在此先记录 ...