注意数据范围,十位数以上就可以考虑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. Django2.0 URL配置

    一.实例 先看一个例子: from django.urls import path from . import views urlpatterns = [ path('articles/2003/', ...

  2. Unity2017烘焙参数设置

  3. Confluence 6 使用 LDAP 授权连接一个内部目录 - 用户 Schema 设置

    请注意:这部分仅在拷贝用户登录(Copy User on Login)功能被启用后可见. 其他用户 DN(Additional User DN) 这个值被用在进行用户查找和载入的时候来针对 base ...

  4. 『Scipy』常用方法记录

    优化器使用教程 J = lambda wb: self.get_cost_grad(wb, X, Y_one_hot) theta = self.wb_init(X,Y_one_hot) result ...

  5. n转m进制标准写法(必须记忆)

    #include <bits/stdc++.h> using namespace std; int main() { int n,m; cin >> n >> m; ...

  6. exec可以用来执行语句的

    set @sql='select * from '+@table print @sql exec(@sql)

  7. Linux文件与目录管理(二)

    一.处理目录的常用命令 ls:列出目录 cd:切换目录 pwd:显示当前的目录 mkdir:创建一个新的目录 rmdir:删除一个空的目录 cp:复制文件或者目录 rm:移除文件或者目录 可以使用ma ...

  8. springmvc基础流程

    转载:http://blog.csdn.net/zuoluoboy/article/details/19766131 注意:springmvc多个拦截器执行流程:每个拦截器的方法preHandler顺 ...

  9. JAVA并行程序基础

    JAVA并行程序基础 一.有关线程你必须知道的事 进程与线程 在等待面向线程设计的计算机结构中,进程是线程的容器.我们都知道,程序是对于指令.数据及其组织形式的描述,而进程是程序的实体. 线程是轻量级 ...

  10. oracle图形界面配置tns

    oracle图形界面配置tns       启动orcl服务