ACM: POJ 1401 Factorial-数论专题-水题

时间:2021-10-27 10:06:14
POJ 1401 Factorial

Time Limit:1500MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

 

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
/*/
题意: n!后缀0的个数; 这里要注意到只有2的倍数和5的倍数相乘会产生后缀0; 毫无疑问2的倍数比5多,所以只要统计5的倍数的个数就行了; 但是要注意,5^n能产生n个后缀0; 所以就要处理一下,把5^i (i=1~n)的所有5的倍数全部加起来,详情看代码; AC代码
/*/
#include"map"
#include"cmath"
#include"string"
#include"cstdio"
#include"vector"
#include"cstring"
#include"iostream"
#include"algorithm"
using namespace std;
typedef long long LL;
const int MX=202;
#define memset(x,y) memset(x,y,sizeof(x))
#define FK(x) cout<<"【"<<x<<"】"<<endl LL ans(int n) {
LL ans = 0;
for (int i=5; n/i>0; i*=5) { //5的倍数能产生1个0,25的倍数能产生2个0, 125的倍数能产生3个0,以此类推。。。
ans+=n/i;
}
return ans;
} int main() {
int T,x;
scanf("%d",&T);
while(T--) {
scanf("%d",&x);
printf("%d\n",ans(x));
}
}

  

ACM: POJ 1401 Factorial-数论专题-水题的更多相关文章

  1. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include&lt ...

  2. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  3. POJ 3984 - 迷宫问题 - &lbrack;BFS水题&rsqb;

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  4. poj 1007&colon;DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  5. poj 1004&colon;Financial Management(水题,求平均数)

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 126087   Accepted: ...

  6. POJ 3176 Cow Bowling (水题DP)

    题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...

  7. 【数论,水题】UVa 10127 - Ones

    题目链接 题意:给你一个数n,问最少有多少个1构成的“1”串(1,11,...)能整除n; 比如:111能被3整除: 111111能被7整除:... 作为水货觉得只要自己能1A的都是水题=. = #i ...

  8. poj 1658 Eva&&num;39&semi;s Problem&lpar;水题&rpar;

    一.Description Eva的家庭作业里有很多数列填空练习.填空练习的要求是:已知数列的前四项,填出第五项.因为已经知道这些数列只可能是等差或等比数列,她决定写一个程序来完成这些练习. Inpu ...

  9. HDU ACM 1073 Online Judge -&amp&semi;gt&semi;字符串水题

    分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...

随机推荐

  1. Fibonacci 2

    Fibonacci 2 感谢613的提供的题面 题目描述 给定\(S_0,S_1\),\(S_n=S_{n-1}+S_{n-2}+F_nF_{n-1}\),求\(S_n\bmod 2^{32}\). ...

  2. Bower In ASP&period;NET Core

    创建一个ASP.NET Core MVC项目的时候,会产生一个bower.json的文件,用于管理前段的js. NPM & Bower NPM主要运用于Node.js项目的内部依赖包管理,安装 ...

  3. 利用改进的cca算法,进行识别

    这个方法,很有意思,第一,不用降维:第二,跟ica做比较,竟然说比强大的ica还好: 看来,国防科大的博士,还是很牛的. <OI and fMRI Signal Separation Using ...

  4. My way to Python - Day05 - 面向对象-思维导图

    My way to Python - Day05 - 面向对象   思维导图

  5. easyUI combobox combotree 模糊查询&comma;带上下键选择功能,待完善。。。。

    /2017年4月9日 11:52:36 /** * combobox和combotree模糊查询 * combotree 结果带两级父节点(手动设置数量) * 键盘上下键选择叶子节点 * 键盘回车键设 ...

  6. Cent Linux启动tomcat慢的问题

    Tomcat7的session id的生成主要通过java.security.SecureRandom生成随机数来实现,随机数算法使用的是”SHA1PRNG”. 是因为一个JDK一个bug,在这个bu ...

  7. Bugzilla使用规范

    登陆Bugzilla Bugzilla登陆地址: http://172.21.8.39:21500/manual/ 账号:XXX@sim.com 密码:123456 Bugzilla简介 Bugzil ...

  8. Could not find com&period;android&period;tools&period;build&colon;gradle&colon;3&period;0&period;0-alpha1 in circle ci

      Error:(1, 0) The android gradle plugin version 3.0.0-alpha1 is too old, please update to the lates ...

  9. Jmeter4&period;0----HTTP Cookie管理器(9)

    1.说明 在脚本编写的过程中,我们常常会遇到用户登录之后的相关操作,但是又不想去通过脚本先模拟用户登录,再使用cookie值保持登录,做后续的操作的情况下,我们就会用到HTTP Cookie管理. H ...

  10. CentOS7自动补齐

    cenos7,最小安装,做服务器嘛.但是发现tab键的自动补齐功能没有:其实可以直接把centos7作为yum源,然后直接安装bash-completion  yum install -y bash- ...