博客1
因子个数
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define maxn 3000025
bool prime[maxn];
int cnt;
ll Prime[maxn], num[maxn], mini[maxn];
void make_(){
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
num[1] = 1;
for(int i = 2 ; i < maxn ; ++ i){
if(prime[i]){
Prime[++cnt] = i;
num[i] = 2;
mini[i] = 1;
}
for(int j = 1 ; j <= cnt && i * Prime[j] < maxn ; ++ j){
prime[i * Prime[j]] = false;
if(i % Prime[j] == 0){
mini[i * Prime[j]] = mini[i] + 1;
num[i * Prime[j]] = num[i] / (1 + mini[i]) * (1 + mini[i * Prime[j]]);
break;
}
else{
num[i * Prime[j]] = num[i] * num[Prime[j]];
mini[i * Prime[j]] = 1;
}
}
}
}
int main()
{
make_();
return 0;
}
因子和
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define maxn 3000025
bool prime[maxn];
int cnt;
ll Prime[maxn], num[maxn], mini[maxn];
void make_(){
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
num[1] = 1;
for(int i = 2 ; i < maxn ; ++ i){
if(prime[i]){
Prime[++cnt] = i;
num[i] = 1 + i;
mini[i] = 1 + i;
}
for(int j = 1 ; j <= cnt && i * Prime[j] < maxn ; ++ j){
prime[i * Prime[j]] = false;
if(i % Prime[j] == 0){
mini[i * Prime[j]] = num[i] * Prime[j] + 1;
num[i * Prime[j]] = num[i] / mini[i] * mini[i * Prime[j]];
break;
}
else{
num[i * Prime[j]] = num[i] * num[Prime[j]];
mini[i * Prime[j]] = 1 + Prime[j];
}
}
}
}
int main()
{
make_();
return 0;
}