题目大意
对于任意一个(a_i, 1leq i leq n)问是否存在两个(a_i)的因数(d_1, d_2)满足(gcd(d_1+d_2, a_i)=1)
解题思路
如果(gcd(x, y) = 1),那么(gcd(x+y, x imes y) = 1)。如果一个数不是质数,就把他的一个质因子当a,(a_i / a)当b,a和b正好满足条件。
代码
const int maxn = 1e7+10;
int u[maxn], p[maxn], a[maxn], b[maxn];
int main() {
IOS;
for (int i = 2; i<maxn; ++i) {
if (!u[i]) u[i] = p[++p[0]] = i;
for (int j = 1; i*p[j]<maxn; ++j) {
u[i*p[j]] = p[j];
if (i%p[j]==0) break;
}
}
int n; cin >> n;
for (int i = 1; i<=n; ++i) {
int num; cin >> num;
vector<int> tmp;
int f = 1, t = num;
for (int j = 1; 1LL*p[j]*p[j]<=num; ++j)
if (num%p[j]==0) {
while(num%p[j]==0) {
num /= p[j];
if (tmp.empty()) f *= p[j];
}
tmp.push_back(p[j]);
}
if (num>1) tmp.push_back(num);
if (f!=1 && t/f!=1) a[i] = f, b[i] = t/f;
else a[i] = b[i] = -1;
}
for (int i = 1; i<=n; ++i) cout << a[i] << (i==n ? '
':' ');
for (int i = 1; i<=n; ++i) cout << b[i] << (i==n ? '
':' ');
return 0;
}