注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要。

原题:

1065.   Factorial


Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 6067   Accepted Runs: 2679

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

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的更多相关文章

  1. TJU Problem 2101 Bullseye

    注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...

  2. TJU Problem 2548 Celebrity jeopardy

    下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548.   Celebrity jeopardy Time Limit: 1.0 Seconds   Memory Lim ...

  3. TJU Problem 2857 Digit Sorting

    原题: 2857.   Digit Sorting Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 3234   Accepted ...

  4. TJU Problem 1015 Gridland

    最重要的是找规律. 下面是引用 http://blog.sina.com.cn/s/blog_4dc813b20100snyv.html 的讲解: 做这题时,千万不要被那个图给吓着了,其实这题就是道简 ...

  5. TJU Problem 1100 Pi

    注: 1. 对于double计算,一定要小心,必要时把与double计算相关的所有都变成double型. 2. for (int i = 0; i < N; i++)         //N 不 ...

  6. TJU Problem 2520 Quicksum

    注意: for (int i = 1; i <= aaa.length(); i++) 其中是“ i <= ",注意等号. 原题: 2520.   Quicksum Time L ...

  7. TJU Problem 1090 City hall

    注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型. 原题: 1090.   City hall Time Limit: 1.0 Seconds   Memory ...

  8. TJU Problem 1644 Reverse Text

    注意: int N; cin >> N; cin.ignore(); 同于 int N; scanf("%d\n",&N); 另:关于 cin 与 scanf: ...

  9. LeetCode Day4——Factorial Trailing Zeroes

    /* * Problem 172: Factorial Trailing Zeroes * Given an integer n, return the number of trailing zero ...

随机推荐

  1. [ios]MKMapView中使用MKPolyline画线

    参考:http://blog.sina.com.cn/s/blog_9e8867eb0101dt76.html 首先在MapView.h中 #import <MapKit/MapKit.h> ...

  2. android二级listview列表

    今天来实现以下大众点评客户端的横向listview二级列表,先看一下样式. 这种横向的listview二级列表在手机软件上还不太常见,但是使用过平板的都应该知道,在平板上市比较常见的.可能是因为平板屏 ...

  3. 如何查看DNS?

    查看dns服务ip:    命令: ipconfig/all  查看dns缓存:    命令:ipconfig/displaydns     强制更新缓存:    命令:ipconfig /flush ...

  4. PHP算法之排序算法(PHP内置排序函数)

    首先用实例来讲述一下PHP内置的一些排序函数 [a / k] sort [/ rsort]:[保留索引关系 / 按键名(保留键名关系,适用于关联数组)] 对数组进行排序,结束时数组单元将被从最低到最高 ...

  5. 你真的了解Spring Framework吗?

    Java 框架 上世纪90年代,使用Java开发Web应用普遍使用J2EE标准,J2EE具有平台无关性,对事务.消息等企业级的特性都有很好的支持,但当时的J2EE仍存在一些问题: 非常复杂:EJB的诞 ...

  6. rsync+inotify文件同步

    rsync+inotify文件同步 在服务器中,通常结合计划任务.shell脚本来执行本地备份.为了进一步提高备份的可靠性,使用异地备份也是非常重要的,利用rsync工具,可以实现快速.高效的异地备份 ...

  7. 插件Vue.Draggable(5000🌟)

    安装资源库:从Vue资源:https://github.com/vuejs/awesome-vue下载 Libraries/UI Components/Form/Drag and Drop yarn ...

  8. codeforces 571a//Lengthening Sticks// Codeforces Round #317

    题意:三角形3条边,最多共添加ll长,问组成的合法三角形个数. 本来想用暴搜,觉得会超时就搜题解了.不过保证我解释得更清晰. 先计算ll长分配给3条边有几种分法?由于不分也是合法的,因此最后实际分出去 ...

  9. 基于DOMContentLoaded实现文档加载完成后执行的方法

    我们有时可能需要一些在页面加载完成之后执行的方法,其实js原生就提供了onload方法,所以我们最简单的办法就是直接给onload赋值一个函数,在页面加载完成之后就会自动执行 widnow.onloa ...

  10. CodeForces 558B

    Description Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make ...