AT_abc400_e [ABC400E] Ringo's Favorite Numbers 3 题解
Snowflake_Fairy · · 题解
题目大意
正整数
-
- 对于
N 的每个素因子p ,p 将整除N 偶数次。更正式地说,最大非负整数k 使得p^k 整除N 且k 是偶数。
有
解题思路
我们使用筛法筛出所有素数并打上标记,然后再跑一遍,计算每个数
对于每次询问
CODE:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int cnt[N], ans[N];
bool isprime[N];
inline void shai() {
for (int i = 2; i <= 1e6; ++i) {
if (!isprime[i]) {
for (int j = i + i; j <= 1e6; j += i) {
isprime[j] = true;
}
}
}
for (int i = 2; i <= 1e6; ++i)
if (!isprime[i]) {
for (int j = i; j <= 1e6; j += i) {
cnt[j]++;
}
}
for (int i = 6; i <= 1e6; ++i) {
if (cnt[i] == 2) {
ans[i] = i;
} else {
ans[i] = ans[i - 1];
}
}
}
signed main() {
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
shai();
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
n = ans[(int)sqrtl(n)];
cout << n * n << "\n";
}
return 0;
}