English, asked by kallesurekha2001, 14 hours ago

Cubical Subsets
You are given two sets of numbers A and B. You should find a subset A' of A and another subset B' of B
such that:
1. A' and B' are non-empty.
2. For each element a in A' and each element b in B', a*b is a perfect cube.
3. IA' ^2 + IB'I^2 is maximized (we denote by A' | the number of elements of A', the same goes for
B'T).
Input Format:
W
The first line contains an integer T representing the number of test cases that will follow.
Each test case consists of three lines:
The first line contains two integer N and M, representing the size of A and the size of B, respectively.
The second line contains the N values of A.
The third line contains the M values of B.
Constraints:
1STS 10^4
15 NM 5*10^5
The sum of N + M for all the T tests is between 1 and 5 * 10^5.
The elements of A and B are integers between 1 and 10^6.
Output Format:
Output Tlines, each containing the answer for one test.
If there is no solution, the line should contain -1, otherwise output the maximum possible value of
TA'^2+B'T^2
sample input
1
3 2
2 16 5
4 4
sample output
8
Explanation:
in this test case,we have a subset [2,16] in A, and [4,4] in B which satisfies all conditions. Each element a in A's and each element b in B', a*b is a perfect cube, like (2*4=8),(2*4=8),(18*4=64),(16*4=64).
Now |A|^2+|B|^2 is maximized hence 2^2+2^2=8​

Answers

Answered by hardik7033
0

Answer:

Cubical Subsets

You are given two sets of numbers A and B. You should find a subset A' of A and another subset B' of B

such that:

1. A' and B' are non-empty.

2. For each element a in A' and each element b in B', a*b is a perfect cube.

3. IA' ^2 + IB'I^2 is maximized (we denote by A' | the number of elements of A', the same goes for

B'T).

Input Format:

W

The first line contains an integer T representing the number of test cases that will follow.

Each test case consists of three lines:

The first line contains two integer N and M, representing the size of A and the size of B, respectively.

The second line contains the N values of A.

The third line contains the M values of B.

Constraints:

1STS 10^4

15 NM 5*10^5

The sum of N + M for all the T tests is between 1 and 5 * 10^5.

The elements of A and B are integers between 1 and 10^6.

Output Format:

Output Tlines, each containing the answer for one test.

If there is no solution, the line should contain -1, otherwise output the maximum possible value of

TA'^2+B'T^2

sample input

1

3 2

2 16 5

4 4

sample output

8

Explanation:

in this test case,we have a subset [2,16] in A, and [4,4] in B which satisfies all conditions. Each element a in A's and each element b in B', a*b is a perfect cube, like (2*4=8),(2*4=8),(18*4=64),(16*4=64).

Now |A|^2+|B|^2 is maximized hence 2^2+2^2=8

Answered by AdilD40l
0

Sorry Bro I don't know the answer

Similar questions