TJU Problem 1065 Factorial
注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要。
原题:
1065. Factorial
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 6067 Accepted Runs: 2679
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
Source: Central European
2000
源代码:
#include <iostream>
#include <cmath>
using namespace std; long long int a[]; int main() {
for (int i = ; i < ; i++) {
a[i] = pow(, i+);
}
int N; cin >> N;
while(N--) {
long long int num, temp, count = -; cin >> num;
temp = num;
while (temp != ) {
temp /= ;
//cout << "temp " << temp << endl;
count++;
}
//cout << "count " << count << endl;
if (count == ) {
cout << << endl;
continue;
}
//cout << "num " << num << endl;
long long int temp2 = num / a[count - ];
//cout << "temp2 " << temp2 << endl;
long long int res, sum = temp2 * count;
for (int i = count - ; i >= ; i--) {
int temp1 = num / a[i];
sum += (temp1 - temp2) * (i+);
temp2 = temp1;
}
cout << sum << endl;
}
return ;
}
TJU Problem 1065 Factorial的更多相关文章
- TJU Problem 2101 Bullseye
注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...
- TJU Problem 2548 Celebrity jeopardy
下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548. Celebrity jeopardy Time Limit: 1.0 Seconds Memory Lim ...
- TJU Problem 2857 Digit Sorting
原题: 2857. Digit Sorting Time Limit: 1.0 Seconds Memory Limit: 65536KTotal Runs: 3234 Accepted ...
- TJU Problem 1015 Gridland
最重要的是找规律. 下面是引用 http://blog.sina.com.cn/s/blog_4dc813b20100snyv.html 的讲解: 做这题时,千万不要被那个图给吓着了,其实这题就是道简 ...
- TJU Problem 1100 Pi
注: 1. 对于double计算,一定要小心,必要时把与double计算相关的所有都变成double型. 2. for (int i = 0; i < N; i++) //N 不 ...
- TJU Problem 2520 Quicksum
注意: for (int i = 1; i <= aaa.length(); i++) 其中是“ i <= ",注意等号. 原题: 2520. Quicksum Time L ...
- TJU Problem 1090 City hall
注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型. 原题: 1090. City hall Time Limit: 1.0 Seconds Memory ...
- TJU Problem 1644 Reverse Text
注意: int N; cin >> N; cin.ignore(); 同于 int N; scanf("%d\n",&N); 另:关于 cin 与 scanf: ...
- LeetCode Day4——Factorial Trailing Zeroes
/* * Problem 172: Factorial Trailing Zeroes * Given an integer n, return the number of trailing zero ...
随机推荐
- C#匹配中文
public static bool ContainsChinese(string text) { if (string.IsNullOrEmpty(text)) return false; stri ...
- IIS8.5支持WCF
昨天写了个WCF例子,在我电脑上怎么发布都不成功,老是报错. 后来把这个例子放到其他人电脑上发布都没问题,这应该就是我IIS的问题了.我用的是win8.1的系统,IIS版本是8.5,IIS8.5默认是 ...
- [.NET开发] C# 合并、拆分PDF文档
在整理文件时,将多个同类型文档合并是实现文档归类的有效方法,也便于文档管理或者文档传输.当然,也可以对一些比较大的文件进行拆分来获取自己想要的部分文档.可以任意地对文档进行合并.拆分无疑为我们了提供极 ...
- t-SNE 聚类
一个有效的数据降维的方法 t-SNE,类似PCA的主成分降维分析. 参考: t-分布邻域嵌入算法(t-SNE algorithm)简单理解 t-SNE初学 很好的教程:An illustrated i ...
- ural Ambitious Experiment 树状数组
During several decades, scientists from planet Nibiru are working to create an engine that would all ...
- MySQL Replication 线程(理解详细过程)
Replication 线程 Mysql 的Replication 是一个异步的复制过程,从一个Mysql instace(我们称之为Master)复制到另一个Mysql instance(我们称之S ...
- hdu-1849-nim模板
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- python运维之使用python进行批量管理主机
1. python运维之paramiko 2. FABRIC 一个与多台服务器远程交互的PYTHON库和工具 3. SSH连接与自动化部署工具paramiko与Fabric 4. Python批量管理 ...
- Animation鱼眼效果
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> < ...
- OC MRC之autorelease问题(代码分析)
// // main.m // 08-autorelease // // Created by apple on 13-8-9. // Copyright (c) 2013年 itcast. All ...