求某个数n的某一个因子的个数 (高斯取整函数思想)

来源:互联网 发布:詹姆斯生涯数据统计 编辑:程序博客网 时间:2024/06/06 00:53

Description

三胖真的是二到了一种程度,近来屡屡出怪招,惹得周边同学不安,同桌的惠姑娘更是一直担惊受怕。这不,前天三胖在惠同学的作业本上划道道,昨天用铅笔在惠同学的手上刺了一下,不知道今天他又有什么举动,班长看在眼里,恨在心里。班长昨天就准备过去揍他一顿,但碍于副班长的脸面才没有动手。现在我们需要判断一下三胖二的程度,它是有他的脑残值n!决定的,也就是n!有几个2的因子。一段时间中每天的脑残值是不同的,现在给你几天时间的脑残值n!,计算他二的程度。

Input

第一行是一个正整数t(0<t<50)表示测试数据组数。接着有t个正整数n,(0<n<10^18),其中n!表示脑残值

Output

对每一个测试数据n,输出一个正整数表示对应的二的程度的数。

Sample Input

32415

Sample Output

1311


分析:以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

n!mod10k=0

Input

There are several test cases, please process till EOF.

For each test case, there is only one line contains integer n (1n109).

Output

For each test case, output the answer in one line.

Examples

input
25
output
01
#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;    }}


1 0