题解报告:hdu 1124 Factorial(求N!尾数有多少个0。)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1124
Problem Description
ACM technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem is so called "Travelling Salesman Problem" and it is very hard to solve. If we have N BTSes to be visited, we can visit them in any order, giving us N! possibilities to examine. The function expressing that number is called factorial and can be computed as a product 1.2.3.4....N. The number is very high even for a relatively small N.
The programmers understood they had no chance to solve the problem. But because they have already received the research grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behaviour of the factorial function.
For example, they defined the function Z. For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbers N1<N2, then Z(N1) <= Z(N2). It is because we can never "lose" any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently.
Input
Output
Sample Input
Sample Output
#include<iostream>
using namespace std;
int main(){
int n,t,cnt;
while(cin>>t){
while(t--){
cin>>n;cnt=;
while(n>)cnt+=n/,n/=;
cout<<cnt<<endl;
}
}
return ;
}
题解报告:hdu 1124 Factorial(求N!尾数有多少个0。)的更多相关文章
- HDU 1124 Factorial (数论)
http://acm.hdu.edu.cn/showproblem.php? pid=1124 題目好長好長,好可怕,看完腎都萎了,以後肯定活不長.我可不能死在這種小事上,小灰灰我勵志死在少女的超短裙 ...
- hdu 1124 Factorial(数论)
题意: 求n!的尾0的个数 分析: 0一定是由因子2和5相乘产生的: 2的个数显然大于5的个数,故只需统计因子5的个数 n/5不能完全表示n!中5的个数(egg: 25),应该n/=5后,累加上n/2 ...
- HDU 1124 Factorial (阶乘后缀0)
题意: 给一个数n,返回其阶乘结果后缀有几个0. 思路: 首先将n个十进制数进行质因数分解,观察的得到只有2*5才会出现10.那么n!应含有min(2个数,5个数)个后缀0,明显5的个数必定比2少,所 ...
- 求N!尾数有多少个0。
方法一:假设N!=K*10M,K不能被10整除,那么N!尾数就有M个0.再对N!进行质因子分解:N!=2x*3y*5z...由于10=2*5,即每一对2和5相乘都可以得到1个0,所以M只与指数x.z有 ...
- 题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- 题解报告:hdu 2069 Coin Change(暴力orDP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...
- 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)
Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...
- 2015浙江财经大学ACM有奖周赛(一) 题解报告
2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...
- cojs 强连通图计数1-2 题解报告
OwO 题目含义都是一样的,只是数据范围扩大了 对于n<=7的问题,我们直接暴力搜索就可以了 对于n<=1000的问题,我们不难联想到<主旋律>这一道题 没错,只需要把方程改一 ...
随机推荐
- POJ2573 Bridge 经典的过桥问题
曾经遇到过类似的.纪念一下!这题同一时候也是 ZOJ1877.经典的过桥问题 是有个博客解说的非常好的 戳这里 挺久曾经.遇到过一个基本一样的,那个题目仅仅要求求出 最短时间就可以,如今还有过桥的过 ...
- SQL yog过期后教你怎么让他不过期
打开注册表 安装sqlyog后,进入注册表编辑器,进入\HEYK_CURRENT_USER\Software\,找到以{}括起来的那项直接干掉! 1, regedit 2,修改 3,
- 【问题记录】LoadRunner 接口压测-json格式报文
[问题起因] 前段时间,协助其他项目录制接口压测脚本,对方要求请求报文内容实现参数化. 请求方法如下: 直接在Parameter List中新增一个parameter, 将请求报文放入dat文件中.这 ...
- 暴力破解zip文件
#coding=utf-8 """ 用户输入-z参数指定要破解的zip文件,输入-d参数输入字典文件,即可暴力破解加密的zip文件 """ ...
- 纯JS写的一款记录事项的单页应用
要点: 1.使用localStorage存储 2._change_record_progress函数以字符串作为参数,用eval执行这个参数 3.使用了jQuery自定义事件,便于数据改变时实时更新显 ...
- 比 git log 更强大的 git reflog
最近做了个骚操作 git checkout commitId 修改了部分内容 git add . git commit -m '修改了些东西' -> 此时git 会自动生成一个新的 comm ...
- SQL Server 存储过程具体解释
SQL Server 存储过程具体解释 存储过程的优缺点 ◆长处: 运行速度更快. 存储过程仅仅在创造时进行编译,而一般SQL语句每运行一次就编译一次,所以使用存储过程运行速度更快. 存储过程用于处理 ...
- css hack原理
近期看了几篇关于css hack的文章,认为不错整理一下. css hack非常多人不理解它的原理,事实上大家都知道对于不同的浏览器,CSS的解析程度不一样.因此会导致生成的页面效果不一样:特别是对于 ...
- 【solr专题之中的一个】Solr高速入门
一.Solr学习相关资料 1.官方材料 (1)高速入门:http://lucene.apache.org/solr/4_9_0/tutorial.html.以自带的example项目高速介绍发Solr ...
- ABAP文件加密解密-PGP
1.SM69创建命令 2.解密 DATA: lv_para = '--passphrase (key) -o /oracle/sfdata/sfdata.csv -d /oracle/sfdata/s ...