简单数学题,我却不会做 - -!!!
Description
The most importantpart of a GSM network is so called Base Transceiver Station (BTS).These transceivers form the areas called cells (this term gave thename to the cellular phone) and every phone connects to the BTSwith the strongest signal (in a little simplified view). Of course,BTSes need some attention and technicians need to check theirfunction periodically.
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" anytrailing zero by multiplying by any positive number. We can onlyget new and new zeros. The function Z is very interesting, so weneed a computer program that can determine its valueefficiently.
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" anytrailing zero by multiplying by any positive number. We can onlyget new and new zeros. The function Z is very interesting, so weneed a computer program that can determine its valueefficiently.
Input
There is a singlepositive integer T on the first line of input. It stands for thenumber of numbers to follow. Then there is T lines, each containingexactly one positive integer number N, 1 <= N<= 1000000000.
Output
For every number N,output a single line containing the single non-negative integerZ(N).
Sample Input
6 3 60 100 1024 23456 8735373
Sample Output
0 14 24 253 5861 2183837 求N的阶层,然后求结果的末尾有多少个0 其实很简单 只是我这等刚入门弱菜想不到而已 每次乘以5的时候 就会多出一个0 所以找出5的倍数有多少个吧 代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
long long i,j,m,n,k,a;
scanf("%I64d",&n);
while(n--)
{
scanf("%I64d",&k);
a=5;
long long num=0;
while(a<=1000000000)
{
num+=k/a;
a*=5;
}
printf("%I64d\n",num);
}
}