跳到正文

题解

题解:AT_abc400_e [ABC400E] Ringo's Favorite Numbers 3

small_lemon_qwq约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年1月14日
更新
2026年1月14日
篇幅
约 1 分钟

版本

  1. v1当前

条件等价于 NN 是 X2X^2,且 XX 只有两个质因子。

用埃氏筛即可。

C++
#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;
}
原文