HDU:1124 Factorial
来源:互联网 发布:怎样退出淘宝客推广 编辑:程序博客网 时间:2024/04/29 12:17
这题真悲剧啊,这么简单的一个题,题意竟然没看懂!
题意:求N!的结果中0的个数,就是求2和5的组合一共有几个,因为2的个数永远大于5的个数,所以只用求出5的因子个数即可,首先算5的因子,然后是5*5的因子……
相加即得结果。
Factorial
Time Limit: 2000/1000 MS(Java/Others)
Total Submission(s):1152
Problem Description
The most important part of a GSM networkis so called Base Transceiver Station (BTS). These transceiversform the areas called cells (this term gave the name to thecellular phone) and every phone connects to the BTS with thestrongest signal (in a little simplified view). Of course, BTSesneed some attention and technicians need to check their functionperiodically.
ACM technicians faced a very interesting problem recently. Given aset of BTSes to visit, they needed to find the shortest path tovisit all of the given points and return back to the centralcompany building. Programmers have spent several months studyingthis problem but with no results. They were unable to find thesolution fast enough. After a long time, one of the programmersfound this problem in a conference article. Unfortunately, he foundthat the problem is so called "Travelling Salesman Problem" and itis very hard to solve. If we have N BTSes to be visited, we canvisit them in any order, giving us N! possibilities to examine. Thefunction expressing that number is called factorial and can becomputed as a product 1.2.3.4....N. The number is very high evenfor 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 thegovernment, they needed to continue with their studies and produceat least some results. So they started to study behaviour of thefactorial function.
For example, they defined the function Z. For any positive integerN, Z(N) is the number of zeros at the end of the decimal form ofnumber N!. They noticed that this function never decreases. If wehave two numbers N1<N2, then Z(N1) <=Z(N2). It is because we can never "lose" any trailing zero bymultiplying by any positive number. We can only get new and newzeros. The function Z is very interesting, so we need a computerprogram that can determine its value efficiently.
ACM technicians faced a very interesting problem recently. Given aset of BTSes to visit, they needed to find the shortest path tovisit all of the given points and return back to the centralcompany building. Programmers have spent several months studyingthis problem but with no results. They were unable to find thesolution fast enough. After a long time, one of the programmersfound this problem in a conference article. Unfortunately, he foundthat the problem is so called "Travelling Salesman Problem" and itis very hard to solve. If we have N BTSes to be visited, we canvisit them in any order, giving us N! possibilities to examine. Thefunction expressing that number is called factorial and can becomputed as a product 1.2.3.4....N. The number is very high evenfor 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 thegovernment, they needed to continue with their studies and produceat least some results. So they started to study behaviour of thefactorial function.
For example, they defined the function Z. For any positive integerN, Z(N) is the number of zeros at the end of the decimal form ofnumber N!. They noticed that this function never decreases. If wehave two numbers N1<N2, then Z(N1) <=Z(N2). It is because we can never "lose" any trailing zero bymultiplying by any positive number. We can only get new and newzeros. The function Z is very interesting, so we need a computerprogram that can determine its value efficiently.
Input
There is a single positive integer T onthe first line of input. It stands for the number of numbers tofollow. Then there is T lines, each containing exactly one positiveinteger number N, 1 <= N <=1000000000.
Output
For every number N, output a single linecontaining the single non-negative integer Z(N).
Sample Input
6 3 60 1001024 23456 8735373
Sample Output
0 14 24 2535861 2183837
Source
Central Europe 2000
代码如下:
#include<stdio.h>
int main()
{
int m,n,num;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
num=0;
while(m!=0)
{
m=m/5;
num+=m;
}
printf("%d\n",num);
}
return 0;
}
int main()
{
}
- HDU:1124 Factorial
- Factorial hdu 1124
- HDU 1124 Factorial
- HDU 1124 Factorial
- HDU 1124 Factorial
- hdu 1124 Factorial
- HDU 1124 Factorial
- hdu 1124 Factorial
- HDU 1124 Factorial
- 【数学】 HDU 1124 Factorial
- HDU 1124 Factorial
- HDU 1124 Factorial(数论)
- hdu 1124 Factorial
- 【HDU】 1124 Factorial
- HDU - 1124 Factorial
- HDU HDOJ 1124 Factorial
- hdu 1124 Factorial(数论:推理)
- HDU 1124 Factorial (數論)
- ZZULI 1480 图论的起源
- HDU:1063 POJ:1001 Exponentiat…
- 浙江大学获ACM-ICPC World Finals …
- Unity-水面效果的shader文件
- HDU:1073 Online Judge
- HDU:1124 Factorial
- 并查集 (先转了!)
- ZZULI 1497 Reading Books
- HDU:1165 Eddy's research II
- HDU 2578 Dating with girls(1)
- 算法——博弈论:取石子游戏
- 大整数运算模板(减法)
- 手把手让你爱上Android sdk自带“9妹”(9patch 工具),让Android游戏开发更方便!
- 大整数运算(加法)