CodeForces - 633B A Trivial Problem 数论-阶乘后缀0
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?
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
- 1
- 5
5 6 7 8 9
- 5
- 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.
题目给出后缀0个数,输出n!满足条件的所有n值。
数论题。由于因子里含有偶数,所以非零末尾一定是偶数。产生0的因数一定包含5,所以题目就转化为寻找阶乘因子中含有5的个数。
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<math.h>
- #include<set>
- #include<algorithm>
- #define MAX 1005
- #define INF 0x3f3f3f3f
- using namespace std;
- int a[MAX];
- int main()
- {
- int n,c,i,j;
- scanf("%d",&n);
- c=;
- for(i=;i<=;i++){ //注意这里是枚举阶乘的因子,需要大于后缀0最长的情况
- int ii=i;
- while(ii%==&&ii>){
- c++;
- ii/=;
- }
- if(c==n){
- printf("5\n");
- printf("%d",i);
- for(j=i+;j<=i+;j++){
- printf(" %d",j);
- }
- break;
- }
- else if(c>n){
- printf("0\n");
- break;
- }
- }
- return ;
- }
CodeForces - 633B A Trivial Problem 数论-阶乘后缀0的更多相关文章
- Codeforces 633B A Trivial Problem
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- UVA 10061 How many zero's and how many digits ? (m进制,阶乘位数,阶乘后缀0)
题意: 给出两个数字a和b,求a的阶乘转换成b进制后,输出 (1)后缀中有多少个连续的0? (2)数a的b进制表示法中有多少位? 思路:逐个问题解决. 设a!=k. k暂时不用直接转成b进制. (1 ...
- codeforces 633B B. 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 ...
- HDU 1124 Factorial (阶乘后缀0)
题意: 给一个数n,返回其阶乘结果后缀有几个0. 思路: 首先将n个十进制数进行质因数分解,观察的得到只有2*5才会出现10.那么n!应含有min(2个数,5个数)个后缀0,明显5的个数必定比2少,所 ...
- [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环
E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_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 432D Prefixes and Suffixes (KMP、后缀数组)
题目链接: https://codeforces.com/contest/432/problem/D 题解: 做法一: KMP 显然next树上\(n\)的所有祖先都是答案,出现次数为next树子树大 ...
- [CodeForces - 1225D]Power Products 【数论】 【分解质因数】
[CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...
随机推荐
- sed相关
1 global flag sed 's/xxx/xxx/' inputfile,如果没有带global flag g的话,匹配替换的只是inputfile中的每一行的第一个匹配项.如果带了g的话,才 ...
- php函数: set_include_path
<?php $p =get_include_path(); $p.=PATH_SEPARATOR.'./bp/'; $p.=PATH_SEPARATOR.'./CLI/'; $p.=PATH_S ...
- 安装postgresql碰到Unable to write inside TEMP environment path
搞了半天,原来是 AVAST搞的鬼,把原来注册表的键值改成它自己了.其实应该是 C:\Windows\System32\vbscript.dll The answer in the following ...
- 【题解】P3129高低卡(白金)High Card Low Card
[题解][P3129 USACO15DEC]高低卡(白金)High Card Low Card (Platinum) 考虑贪心. 枚举在第几局改变规则,在改变规则之前,尽量出比它大的最小的牌,在改变规 ...
- ABap-小技巧
if FIELD cn '0123456789'. *&如果字符串包含‘数字’ STOP. endif. 同理到字母‘ABCDEFG*’ 'abcdefg*' '/' '\' 等其它字 ...
- python mmap使用记录
1.写文件 with open('??', 'r+b') as f: with contextlib.closing(mmap.mmap(f.fileno(), size, flags=mmap.MA ...
- gradle 与 gradlew
配置好gradle环境变量后(配置环境变量这里就不说了,可以自行百度),我们就可以在cmd中使用gradle命令了 在cmd中输入: gradle -v 输出如下: 这时说明gradle的环境变量配置 ...
- PAT 甲级 1128. N Queens Puzzle (20) 【STL】
题目链接 https://www.patest.cn/contests/pat-a-practise/1128 思路 可以 对每一个皇后 都判断一下 它的 行,列 ,左右对角线上 有没有皇后 深搜解决 ...
- POJ1226 Substrings ——后缀数组 or 暴力+strstr()函数 最长公共子串
题目链接:https://vjudge.net/problem/POJ-1226 Substrings Time Limit: 1000MS Memory Limit: 10000K Total ...
- js修改div标签中的内容
<div id='divId'>初始文字</div> <script> $(document).ready(function(e){ $('#divId').htm ...