唯一质因数分解定理:
任意一个合数a仅能以一种方式,写成如下的乘积形式:
a a a =$ p1^{e1}\times p2^{e2}\times …\times pr^{er}$
a a a的因子数= ( e 1 + 1 ) × ( e 2 + 1 ) × . . . . × ( e r + 1 ) (e1+1)\times (e2+1)\times ....\times (er+1) (e1+1)×(e2+1)×....×(er+1)
const int N = (int)2e5 + 7;
int noprime[N], pcnt, p[N / 2];
int nump[N / 2], yinzi[N / 2];
int n, m, top;
void getprime(){
pcnt = 0;
memset(noprime, 0, sizeof(noprime));
noprime[0] = noprime[1] = 1;
for(int i = 2; i < N; ++i) {
if(!noprime[i])p[pcnt++] = i;
for(int j = 0; j < pcnt && i * p[j] < N; ++j) {
noprime[i * p[j]] = 1;
if(i % p[j] == 0)break;
}
}
}
void cal(int t){
memset(nump, 0, sizeof(nump));
top = -1;
int tmp = (int)sqrt(t*1.0);
for(int i = 0; i < pcnt && p[i] <= tmp; ++i) {
if(t % p[i] == 0) {
yinzi[++top] = p[i];
while (t % p[i] == 0) {
nump[top] ++;
t /= p[i];
}
}
if(t == 1)break;
}
if(t > 1) {
yinzi[++top] = t;
nump[top] ++;
}
}
n!中因子p的个数可以这样求:
int t = n,sum = 0;
while ( t > 0 ) {
sum += t / p;
t /= p;
}
计算n!中质因子p的个数x的公式为x=⌊n/p⌋+⌊n/p2⌋+⌊n/p3⌋+...
递推式也可以写为f(n)=f(⌊n/p⌋)+⌊n/p⌋
sum即为n!中因子p的个数
x = p1^a1 * p2^a2 * ... * pn^an
x的因数个数为(a1+1)*...*(an+1)