题解 [模拟赛 2022.11.12] Z
不难的构造题,但有点人类智慧。
首先,
那
那正确性呢?先特判
由于
因为比较懒就没筛质数,直接枚举了(
代码:
#include <stdio.h>
typedef long long ll;
int non_sqr_list[107], w_list[107];
bool vis1[107], vis2[107];
inline int non_sqr(int n){
if (vis1[n]) return non_sqr_list[n];
int t = n, ans = 1;
vis1[n] = true;
for (int i = 2; i * i <= n; i++){
if (n % i == 0){
ans *= i;
while (n % i == 0){
n /= i;
}
}
}
if (n > 1) ans *= n;
return non_sqr_list[t] = ans;
}
ll gcd(ll a, ll b){
return b == 0 ? a : gcd(b, a % b);
}
inline int w(ll n){
if (vis2[n]) return w_list[n];
int t = n, ans = 0;
vis2[n] = true;
for (int i = 2; i * i <= n; i++){
if (n % i == 0){
ans++;
while (n % i == 0){
n /= i;
}
}
}
if (n > 1) ans++;
return w_list[t] = ans;
}
int main(){
int t;
scanf("%d", &t);
for (int i = 1; i <= t; i++){
ll n;
scanf("%lld", &n);
if (n % 2 == 0){
printf("%lld %lld\n", n * 2, n);
} else {
for (int j = 2; ; j++){
int x = non_sqr(j), y = non_sqr(j + 1);
if (w(x / gcd(n, x)) == w(y / gcd(n, y))){
printf("%lld %lld\n", n * (j + 1), n * j);
break;
}
}
}
}
return 0;
}