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

  1. 6
  2. 3
  3. 60
  4. 100
  5. 1024
  6. 23456
  7. 8735373

Sample Output

  1. 0
  2. 14
  3. 24
  4. 253
  5. 5861
  6. 2183837

Hint

poj1401

题解:

我们知道0的来源就是2和5的相乘,,那么我们就可以统计2和5 的个数 以小的个数为准,但是很显然2的个数大于5的个数,
注意(4 = 2 * 2 )所以4 是两个2 同样 8是 3 个 2 ,那么我们就可以统计 从 1 到 n 中5 的个数,当然 25 , 50 要统计两遍 ,125 ,250等 要统计 3遍 ,因为 25 = 5 * 5,,50 = 2 *5 *5 ,,125 = 5 * 5 * 5。
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<string>
  6. #include<cmath>
  7. #include<iomanip>
  8. #include<map>
  9. #include<stack>
  10. #include<vector>
  11. #include<queue>
  12. #include<set>
  13. #include<utility>
  14. #include<list>
  15. #include<algorithm>
  16. #include <ctime>
  17. #define max(a,b) (a>b?a:b)
  18. #define min(a,b) (a<b?a:b)
  19. #define swap(a,b) (a=a+b,b=a-b,a=a-b)
  20. #define memset(a,v) memset(a,v,sizeof(a))
  21. #define X (sqrt(5)+1)/2.0
  22. #define maxn 320007
  23. #define N 200005
  24. #define INF 0x3f3f3f3f
  25. #define PI acos(-1)
  26. #define lowbit(x) (x&(-x))
  27. #define read(x) scanf("%d",&x)
  28. #define put(x) printf("%d\n",x)
  29. #define memset(x,y) memset(x,y,sizeof(x))
  30. #define Debug(x) cout<<x<<" "<<endl
  31. #define lson i << 1,l,m
  32. #define rson i << 1 | 1,m + 1,r
  33. #define mod 1000000009
  34. #define e 2.718281828459045
  35. #define eps 1.0e18
  36. #define ll long long
  37. using namespace std;
  38.  
  39. int main()
  40. {
  41. int t;
  42. cin>>t;
  43. while(t--)
  44. {
  45. int n,res=;
  46. cin>>n;
  47. while (n)
  48. {
  49. res+=n/;
  50. n/=;
  51. }
  52. cout<<res<<endl;
  53. }
  54. return ;
  55. }

Factorial(hdu 1124)的更多相关文章

  1. 题解报告:hdu 1124 Factorial(求N!尾数有多少个0。)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1124 Problem Description The most important part of a ...

  2. HDU 1124 Factorial (数论)

    http://acm.hdu.edu.cn/showproblem.php? pid=1124 題目好長好長,好可怕,看完腎都萎了,以後肯定活不長.我可不能死在這種小事上,小灰灰我勵志死在少女的超短裙 ...

  3. hdu 1124 Factorial(数论)

    题意: 求n!的尾0的个数 分析: 0一定是由因子2和5相乘产生的: 2的个数显然大于5的个数,故只需统计因子5的个数 n/5不能完全表示n!中5的个数(egg: 25),应该n/=5后,累加上n/2 ...

  4. HDU 1124 Factorial (阶乘后缀0)

    题意: 给一个数n,返回其阶乘结果后缀有几个0. 思路: 首先将n个十进制数进行质因数分解,观察的得到只有2*5才会出现10.那么n!应含有min(2个数,5个数)个后缀0,明显5的个数必定比2少,所 ...

  5. [SinGuLaRiTy] 组合数学题目复习

    [SinGuLaRiTy] Copyright (c) SinGuLaRiTy 2017.  All Rights Reserved. [CQBZOJ 2011] 计算系数 题目描述 给定一个多项式( ...

  6. hdu 3758 Factorial Simplification

    这题主要是质因数分解!! 求出每个因子的幂,如果有负数,则输出-1: 如果2的幂数为0,这输出0: 最后就是开始凑阶乘了…… #include<iostream> #include< ...

  7. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  8. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  9. 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 ...

随机推荐

  1. Transparent PageRoute in Flutter for displaying a (semi-) transparent page

    import 'package:flutter/widgets.dart'; class TransparentRoute extends PageRoute<void> { Transp ...

  2. Missing artifact com.oracle:ojdbc14:jar:10.2.0.3.0

    1.Missing artifact com.oracle:ojdbc14:jar:10.2.0.3.0操作如下: 2.下载链接:链接:https://pan.baidu.com/s/1Ziyg2jl ...

  3. Domain logic approachs

    1.transaction script(事务脚本) 概述: 很多企业应用可以看成一系列的事务,每一个事务可以通过使用一个Transaction Script来处理. 用法: 使用Transactio ...

  4. Cent OS6下SS+BBR+改SSH端口

    SS+BBR+改SSH端口 (一)搭建SS wget --no-check-certificate -O shadowsocks-libev.sh https://raw.githubusercont ...

  5. docker更改默认仓库地址

    zq@ubuntu:~$ docker pull -h Flag shorthand -h has been deprecated, please use --help Usage: docker p ...

  6. selenium中CSS选择器定位

    selenium元素定位,CSS选择器定位效率会高很多. CSS选择器用于选择你想要的元素的样式的模式.表格摘自“菜鸟教程”,具体用法可去查阅 选择器 示例 示例说明 CSS .class .intr ...

  7. CopyOnWriteArrayList与Collections.synchronizedList的性能对比(转)

    列表实现有ArrayList.Vector.CopyOnWriteArrayList.Collections.synchronizedList(list)四种方式. 1 ArrayList Array ...

  8. python爬虫采集网站数据

    1.准备工作: 1.1安装requests: cmd >> pip install requests 1.2 安装lxml: cmd >>  pip install lxml ...

  9. json处理+list.sort()排序

    #coding:utf-8 """ json是一种轻量级数据交换格式,可以对复杂数据进行表达和存储 规格: 1.数据保存在键值对里 2.键值对之间由逗号分隔 3.花括号用 ...

  10. Java使用Redis--jedis

    参考:菜鸟教程 http://www.runoob.com/redis/redis-java.html 1.Java 使用 Redis 开始在 Java 中使用 Redis 前, 我们需要确保已经安装 ...