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 ...
随机推荐
- jq 插入结构
一.插入 1. append $("#div").append('<a href="baidu.com">a</a>') ; // ...
- android中 检查网络连接状态的变化,无网络时跳转到设置界面
1:在AndroidManifest.xml中加一个声明 <receiver android:name="NetCheckReceiver"> <inten ...
- Codeforces 38B - Chess
38B - Chess 思路:懂点象棋的规则就可以,看看哪些点可以放马. 代码: #include<bits/stdc++.h> using namespace std; #define ...
- CodeForces - 369C - Valera and Elections
369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/std ...
- Codeforces 559B - Equivalent Strings
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...
- asp.net Core MVC + webpack 笔记
webpack 是一个打包工具,用在asp.net Core MVC 会觉得有必要吗? MVC 本身就有bundler~ 如果用过webpack就会知道,打包出来的效果结果就是不一样,MVC的打包就是 ...
- aria2c --enable-rpc --rpc-listen-all -D
在后台启动的方法,如题, 用来配合 web-aria2
- codeforces 55d//Beautiful numbers// Codeforces Beta Round #51
题意:一个数能整除它所有的位上的数字(除了0),统计这样数的个数. 注意离散化,为了速度更快需存入数组查找. 不要每次memset,记录下已有的长度下符合条件的个数. 数位dp肯定是从高位到低位. 记 ...
- codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)
题意:给一个数组,求其中任取2个元素,大的模小的结果最大值. 一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减.那么lower_bound(kx)的前一个就是最优 ...
- Mysql查询用逗号分隔的字段-字符串函数FIND_IN_SET(),以及此函数与in()函数的区别
查询用逗号分隔的字段,可以用字符串函数FIND_IN_SET(): 查询数据库表中某个字段(值分行显示),可以用函数in(). 今天工作中遇到一个问题,就是用FIND_IN_SET()函数解决的. 第 ...