Codeforces Edu89 div2D

Codeforces Edu89 div2D

原题:

You are given n integers a1,a2,…,an.

For each ai find its two divisors d1>1 and d2>1 such that gcd(d1+d2,ai)=1 (where gcd(a,b) is the greatest common divisor of a and b) or say that there is no such pair.

Input
The first line contains single integer n (1≤n≤5⋅105) — the size of the array a.

The second line contains n integers a1,a2,…,an (2≤ai≤107) — the array a.

Output
To speed up the output, print two lines with n integers in each line.

The i-th integers in the first and second lines should be corresponding divisors d1>1 and d2>1 such that gcd(d1+d2,ai)=1 or −1 and −1 if there is no such pair. If there are multiple answers, print any of them.

思路:在d1*d2=k的那一对里面找

ACcodes:

#include <bits/stdc++.h>
const int N = 1e7+10, M = 5e5+10;
int n, a[M], d[M], f[N];
int main() 
{
	scanf("%d", &n);
	f[1]=2; for(int i=2; i<N; i++) f[i]=i;
	for(int i=2; i*i<N; i++) 
		if (f[i]==i)
			for(int j=i*i; j<N; j+=i) 
				if(f[j]==j) 
					f[j]=i;
	for(int i=0; i<n; i++) 
		for(scanf("%d", a+i), d[i]=a[i];d[i]%f[a[i]]==0; d[i]/=f[a[i]]);
	for(int i=0; i<n; i++) 
		printf("%d ", d[i]>1?d[i]:-1); puts("");
	for(int i=0; i<n; i++) 
		printf("%d ", d[i]>1?f[a[i]]:-1);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值