素数问题_算数基本定理

       定理:每个大于1 的正整数n都可以被唯一地写成素数的乘积,在乘积中的素因子按照非降序排列。正整数n的分解式n = p1^a1 * p2^a2****pk^ak 称为n的标准分解式,其中p1, p2, ...pk是素数,p1<p2<....pk, 且a1,a2....ak是正整数。

性质1:若n的标准素因子分解表达式为上面所述,设d(n)为n的素因子的个数,则 

d(n) = (a1+1) * (a2+1) * *** (ak + 1).

      性质2:n!的素因子分解中的素数p的幂为[n/p] + [n/p^2] + [n/p^3] + ........

例题:

n!后面有多少个0

Problem : 118

Time Limit : 1000ms

Memory Limit : 65536K

description

从输入中读取一个数n,求出n!中末尾0的个数。

input

输入有若干行。第一行上有一个整数m,指明接下来的数字的个数。然后是m行,每一行包含一个确定的正整数n,1&lt;=n&lt;=1000000000。

output

对输入行中的每一个数据n,输出一行,其内容是n!中末尾0的个数。

sample_input

3
3
100
1024

sample_output

0
24
253

hint

source

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long int LL ;


int main() {
	int m;
	cin >> m;
	while (m --) {
		LL n;
		cin >> n;
		int num = 5;
		int res = 0;
		while (n /num) {
			res += n/num;
			num *= 5;
		}	
		cout << res << endl;
	}
	
	return 0;
}


posted @ 2015-10-29 15:14  Tovi  阅读(360)  评论(0编辑  收藏  举报