码迷,mamicode.com
首页 > 其他好文 > 详细

Factorial(hdu 1124)

时间:2018-08-30 16:46:13      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:geo   points   use   NPU   computed   station   closed   article   aced   

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

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 
40 int main()
41 {
42     int t;
43     cin>>t;
44     while(t--)
45     {
46         int n,res=0;
47         cin>>n;
48         while (n)
49         {
50             res+=n/5;
51             n/=5;
52         }
53         cout<<res<<endl;
54     }
55     return 0;
56 }
View Code

 

 

Factorial(hdu 1124)

标签:geo   points   use   NPU   computed   station   closed   article   aced   

原文地址:https://www.cnblogs.com/baiyi-destroyer/p/9560678.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!