Factorial(hdu 1124)
Description
The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically.
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
There is a single positive integer T on the first line of input. It stands for the number of numbers to follow. Then there is T lines, each containing exactly one positive integer number N, 1 <= N <= 1000000000.
Output
For every number N, output a single line containing the single non-negative integer Z(N).
Sample Input
6
3
60
100
1024
23456
8735373
Sample Output
0
14
24
253
5861
2183837
Hint
题解:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#include<list>
#include<algorithm>
#include <ctime>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) (a=a+b,b=a-b,a=a-b)
#define memset(a,v) memset(a,v,sizeof(a))
#define X (sqrt(5)+1)/2.0
#define maxn 320007
#define N 200005
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define mod 1000000009
#define e 2.718281828459045
#define eps 1.0e18
#define ll long long
using namespace std; int main()
{
int t;
cin>>t;
while(t--)
{
int n,res=;
cin>>n;
while (n)
{
res+=n/;
n/=;
}
cout<<res<<endl;
}
return ;
}
Factorial(hdu 1124)的更多相关文章
- 题解报告:hdu 1124 Factorial(求N!尾数有多少个0。)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1124 Problem Description The most important part of a ...
- 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少,所 ...
- [SinGuLaRiTy] 组合数学题目复习
[SinGuLaRiTy] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [CQBZOJ 2011] 计算系数 题目描述 给定一个多项式( ...
- hdu 3758 Factorial Simplification
这题主要是质因数分解!! 求出每个因子的幂,如果有负数,则输出-1: 如果2的幂数为0,这输出0: 最后就是开始凑阶乘了…… #include<iostream> #include< ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- leetcode N-Queens/N-Queens II, backtracking, hdu 2553 count N-Queens, dfs 分类: leetcode hdoj 2015-07-09 02:07 102人阅读 评论(0) 收藏
for the backtracking part, thanks to the video of stanford cs106b lecture 10 by Julie Zelenski for t ...
随机推荐
- 内存管理 re模块
# 内存垃圾回收机制: # 工作原理:引用计数 # 引用就+1 释放就是-1 当计数为0时 就会被垃圾回收机制回收 # 标记清除:解决循环引用导致的内存泄漏 # 标记:GC roots可以直接或间接访 ...
- day 07
# 数据类型的相互转化# 字符编码# 文件操作 # 1.哪些类型可以转化为数字# res = int('10')# print(res)# res = int('-3')# print(res)# r ...
- Parhaps you are running on a JRE rather than a JDK?
maven项目启动时报错 解决方案: 第一步:在启动项目上右击 第二步:修改JRE为JDK,双击划线部分 第三步:如果没有配置JDK,进行以下操作 第四步:从本地添加JDK 第五步:应用JDK 选择好 ...
- 算法(第四版)C# 习题题解——1.3
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 这一节内容可能会用到的库文件有 ...
- 含服务端,客户端,数据库的注册/登录/聊天/在线/离线查看的聊天demo
用websocket,mysql,node的写了一个简单聊天的demo 实现了: 注册,登陆功能: 聊天信息广播: 在线/离线状态的查看: 服务端: 主要引用http,fs,mysql,socket. ...
- C# readonly与const区别
静态常量:是指编译器在编译时候会对常量进行解析,并将常量的值替换成初始化的那个值. 动态常量的值则是在运行的那一刻才获得的,编译器编译期间将其标示为只读常量,而不用常量的值代替,这样动态常量不必在声明 ...
- Oracle使用——数据泵导入导出数据库——impdp/expdp使用
使用前提 EXPDP和IMPDP只可以在Oracle服务端使用. EXP导出的文件只可以使用IMP导入,不适用于IMPDP导入文件:EXPDP导出的文件只可以使用IMPDP导入,而不适用于IMP导出文 ...
- HTML和CSS怎么用
首页> 1.HTML和CSS是什么? ·网站和HTML页面 ·简单理解网站 ·一个房子比喻(HTML比喻成房子,CSS为装修) ·页面的整体结构:有树桩标签对嵌套组成 ·页面的组成单元:元素 · ...
- 三.SQL语句
一.mysqladmin客户端命令 1.查看MySQL存活状态 [root@db01 ~]# mysqladmin -uroot -p123 ping 2.查看MySQL状态信息 [root@db01 ...
- Best Practices for Assembly Loading
原文链接 This article discusses ways to avoid problems of type identity that can lead to InvalidCastExce ...