1401 poj Factorial

简单数学题,我却不会做 - -!!!

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.

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);

    }

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值