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)    MemoryLimit: 65536/32768 K (Java/Others)
Total Submission(s):1152    AcceptedSubmission(s): 732


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.
 


 

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;
}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 手机上打不了字怎么办 手机打不了字了怎么办 手机的键盘没了怎么办 微信不能打字了怎么办 电脑输不进去字怎么办 短信在桌面没了怎么办 先锋影音ios没了怎么办 砚台里墨汁干了怎么办 浮石打错了想换怎么办 全蛋打发不起来怎么办 裱花剩下的奶油怎么办 打过头的淡奶油怎么办 淡奶油发过了怎么办 打好的蛋清有水怎么办 想戒烟却坚持不了怎么办 给淮山弄的很痒怎么办 淮山接触皮肤痒怎么办 洗山药后手很痒怎么办 公司老板跑路了怎么办 小工厂老板跑路怎么办 学生医保卡丢了怎么办 在私企年龄大了怎么办 百度网盘上传慢怎么办 百度云盘上传慢怎么办 手机qq打字闪退怎么办 苹果5s手机闪退怎么办 手机qq总是闪退怎么办 qq邮箱密码忘了怎么办 qq加不了群怎么办视频 孩子好几天不大便怎么办 宝宝7天没有大便怎么办 40天小孩不拉屎怎么办 40多天婴儿便秘怎么办 小孩拉绿色稀便怎么办 5岁好几天不拉屎怎么办 2个月宝宝不大便怎么办 两月宝宝不拉屎怎么办 好几天没大便了怎么办 初生婴儿便秘解不出大便怎么办 小孩大便拉不出来怎么办 新生儿3天没大便怎么办