#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1000100;
bool st[N];
int prime[N],idx;
int n;
vector<int> hasFactor[N];
void get_primes(){
for(int i=2;i<=n;i++){
if(st[i]==false){
prime[idx++]=i;
hasFactor[i].push_back(i);
}
for(int j=0;prime[j]*i<=n;j++){
st[prime[j]*i]=true;
if(i%prime[j])
hasFactor[prime[j]*i].push_back(prime[j]);
for(auto t:hasFactor[i])hasFactor[prime[j]*i].push_back(t);
if(i%prime[j]==0)break;
}
}
}
int main()
{
cin>>n;
get_primes();
for(int i=2;i<=n;i++){
cout<<i<<": ";
for(auto j:hasFactor[i])cout<<j<<" ";
cout<<endl;
}
cout<<idx<<endl;
}
质因子筛质数求法
最新推荐文章于 2024-08-30 16:00:44 发布