Description
Input
第一行是一个正整数t(0<t<50)表示测试数据组数。接着有t个正整数n,(0<n<10^18),其中n!表示脑残值
Output
Sample Input
Sample Output
分析:以n=8举例说明。 8!=1*2*3*4*5*6*7*8
第一步:对8除2,相当于将1到8中所有“第一个”2因子提取出来。
第二步:对8除4,相当于将1到8中所有”第二个“2因子提取出来。 ( 比如4由两个2因子组成,8由三个2因子组成,第一步除2相当于把第一个2因子取走,此时4剩下一个2因子,8剩下两个2因子)。
第三步:对8除8,相当于将1到8中所有”第三个“2因子提取出来。
第四步:对8除16,结果为0,退出循环。
当然对于其它数字都是成立的。
代码:
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while(n--){
long long num;
cin >> num;
long long suma = 0;
long long c = 1;
for(int i=1;;i++){
c *= 2;
long long temp = num/c;
if(!temp) break;
else suma+=temp;
}
cout << suma << endl;
}
}
N!
Time limit per test: 1.0 seconds
Time limit all tests: 1.0 seconds
Memory limit: 256 megabytes
Give you an integer
n
, find the maximum
k
that satisfies
Input
There are several test cases, please process till EOF
.
For each test case, there is only one line contains integer n (1≤n≤109) .
Output
For each test case, output the answer in one line.
Examples
2 5
0 1
#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
int main()
{
int n;
while(cin >> n){
int cnt = 0;
int temp = 5;
while(n/temp !=0){
cnt += n/temp;
temp *= 5;
}
cout << cnt << endl;
}
}