注意数据范围,十位数以上就可以考虑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. Jenkins 对项目持续集成的配置之二 API接口自动化 Ant+Jmeter

    先介绍一下Ant+Jmeter 略 我的另一篇文章有讲在linux上部署ant + jmeter以满足CI持续化集成 https://www.cnblogs.com/qianjinyan/p/9067 ...

  2. 02_DllZZ.def

    ZC: 在VC6里面,只要有这个文件就可以了.但是到了 VS2010,需要手动的指定使用这个文件才行:VS2010-->项目-->属性--> 来到窗口"??? 属性页&qu ...

  3. GO 和 KEGG 的区别 | GO KEGG数据库用法 | 基因集功能注释 | 代谢通路富集

    一直都搞不清楚这两者的具体区别. 其实初学者搞不清楚很正常,因为它们的本质是相通的,都是对基因进行归类注释的数据库. 建议初学者自己使用一下这两个数据库,应该很快就能明白其中的区别. (抱歉之前没讲清 ...

  4. English trip -- VC(情景课)5 Around Town

     Around Town  城市周围 Talk about the picture 看图说话 sentences Where are you? I'm in the Meten classroom. ...

  5. 【异常】Application failed to start due to an exception org.springframework.beans.factory.BeanCurrentlyInCreationException

    一. 异常信息:   2018-05-17 18:03:22.224 -DEBUG [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   ...

  6. 1月28日周日,更新ruby到2.5.0版,rvm更新。

    在学习Array的方法的时候,发现文档concat方法可以进行多个数组的添加,而我的不行,猜测是ruby版本没有更新. 查询2.31ruby版本的concat方法,果然和2.5版本的不一样. 于是准备 ...

  7. php--------使用 isset()判断字符串长度速度比strlen()更快

    isset()速度为什么比strlen()更快呢? strlen()函数函数执行起来相当快,因为它不做任何计算,只返回在zval 结构(C的内置数据结构,用于存储PHP变量)中存储的已知字符串长度.但 ...

  8. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.autumn.book/com.autumn.book.MainActivity}: android.os.NetworkOnMainThreadException

    不能把http请求写在主线程里,改为这样 Runnable runnable = new Runnable() { public void run() { HttpClient.post2(" ...

  9. OC 点语法和变量作用域

    一.点语法 (一)认识点语法 声明一个Person类: 1 #import <Foundation/Foundation.h> 2 3 @interface Person : NSObje ...

  10. 自定义Spark Partitioner提升es-hadoop Bulk效率

    http://www.jianshu.com/p/cccc56e39429/comments/2022782 和 https://github.com/elastic/elasticsearch-ha ...