条件等价于 是 ,且 只有两个质因子。
用埃氏筛即可。
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n=1000000,q,f[1000005],g[1000005],h[1000005];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
for(int i=2;i<=n;i++){
if(!f[i]){
g[i]++;
for(int j=2*i;j<=n;j+=i){
g[j]++;
f[j]=1;
}
}
h[i]=h[i-1];
if(g[i]==2){
h[i]=i;
}
}
cin>>q;
while(q--){
int x;
cin>>x;
int t=sqrt(x);
cout<<h[t]*h[t]<<"\n";
}
return 0;
}