#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int x;
cin>>x;
for(int i=2;i<=x/i;i++)
{
if(x%i==0)
{
int s=0;
while(x%i==0)
{
x=x/i;
s++;
}
cout<<i<<" "<<s<<endl;
}
}
if(x>1)cout<<x<<" "<<1<<endl;//如果有大于sqrt(x)的质因数
cout<<endl;
}
}
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1000010;
int cnt=0;
bool st[N];
int prime[N];
void get_prime(int n)
{
for(int i=2;i<=n;i++)
{
if(!st[i]) prime[++cnt]=i;
for(int j=1;prime[j]<=n/i;j++)
{
st[prime[j]*i]=1;
if(i%prime[j]==0) break;
}
}
}
int main()
{
int n;
cin>>n;
get_prime(n);
cout<<cnt;
}
标签:prime,质因数,cout,int,质数,题库,筛选,include
From: https://blog.csdn.net/hui_le4/article/details/140362129