Manthan, Codefest 16 B 数学
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 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 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 is n! = 1·2·3·...·n.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
题意:统计哪些数阶乘的末尾有m位‘0’ 输出个数 并按照升序输出这些数
题解:数学知识 涨姿势
我们知道阶乘下 产生‘0’位只能是 2*5=10产生‘0’位
那么‘0’位的个数取决于‘2’和‘5’的个数
相比之下‘5’的个数更少 所以末尾‘0’的个数取决于阶乘中‘5’的数
所以可以预处理出所有数含有因数‘5’的个数 也就代码中fun的作用
vector存储为一个数x 对应的x!中5的个数也就是结果。
- #include<bits/stdc++.h>
- #define ll __int64
- #define mod 1e9+7
- #define PI acos(-1.0)
- #define bug(x) printf("%%%%%%%%%%%%%",x);
- #define inf 1e8
- using namespace std;
- #define ll __int64
- int fun( int x)
- {
- int flag=;
- if(x%==)
- {
- while(x%==)
- {
- x/=;
- flag++;
- }
- }
- return flag;
- }
- vector<int>ve[];
- int m;
- int main()
- {
- scanf("%d",&m);
- int gg=;
- for(int i=;i<=;i++)
- {
- gg+=fun(i);
- if(gg==m)
- ve[gg].push_back(i);
- }
- printf("%d\n",ve[m].size());
- if(ve[m].size())
- cout<<ve[m][];
- for(int i=;i<ve[m].size();i++)
- cout<<" "<<ve[m][i];
- cout<<endl;
- return ;
- }
Manthan, Codefest 16 B 数学的更多相关文章
- 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 B. A Trivial Problem 二分 数学
B. A Trivial Problem 题目连接: http://www.codeforces.com/contest/633/problem/B Description Mr. Santa ask ...
- Manthan, Codefest 16
暴力 A - Ebony and Ivory import java.util.*; import java.io.*; public class Main { public static void ...
- 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 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵
H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...
- Manthan, Codefest 16 D. Fibonacci-ish
D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard in ...
- 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 ...
- Manthan, Codefest 16 -C. Spy Syndrome 2
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Manthan, Codefest 16 -A Ebony and Ivory
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
随机推荐
- cout对象一些常用方法的总结
cout.precision(n); 这个方法的功能是,设置精度为n,返还值是上一次的设置精度. #include <iostream> using namespace std; int ...
- js当中mouseover和mouseout多次触发(非冒泡)
JS当中,mouseover和mouseout多次触发事件,不光是冒泡会产生,就是不冒泡,在一定条件下 ,也会产生多次触发事件: 例如下面的结构的情况下,我在class="ceng_up f ...
- python-kafka源码解析之socketpair
socket基本操作包括:socket()函数创建socket文件描述符,唯一标识一个socket.bind()函数,将ip:port和socket绑定listen()函数来监听这个socket,假如 ...
- pycharm在同目录下import,pycharm会提示错误,但是可以运行
原因是: pycharm不会将当前文件目录自动加入自己的sourse_path. 解决方案:右键make_directory as-->sources path将当前工作的文件夹加入sou ...
- 背景透明度处理 兼容IE
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 打开POST传参的弹出窗口
//穿件 function openPostPopWindow(url,param,target){ var $form = $("<form></form>&quo ...
- Visual Studio的下载安装
下载地址: 下载Visual Studio Code https://code.visualstudio.com/ 安装扩展包 安装图标 View->Extensions 搜索Icon 安装Ma ...
- ob缓存的基本使用
在页面 加载的时候 如果 图片 很多 很大 会造成页面的阻塞降低用户体验 我们在点击页面的时候可以使用OB缓存 整个页面, 当用户点击的时候直接请求的是我们预先准备好的html页面 .也降低了我们数据 ...
- 牛客练习赛42 A 字符串
题目描述 给定两个等长的由小写字母构成的串 A,BA,B,其中 |A|=|B|=n|A|=|B|=n. 现在你需要求出一个子区间 [l,r][l,r] 使得 LCP(A[l,r],B[l,r])×LC ...
- pycharm中某些方法被标黄的原因及解决办法
在编辑python文件时,会遇到上图所示,函数方法被标黄的问题,但是不影响使用. 引起原因:,如果不报错说明,这是因为你配置的python解释器中有该方法,但是pycharm没有找到这个方法,即加载失 ...