Cubical Subsets
u are given two sets of numbers A and B. You should find a subset A'of A and another subset B' of B such
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. JA'^2 + B'|2 is maximized (we denote by JA'| the number of elements of A', the same goes for
put Format:
e first line contains an integer T representing the number of test cases that will follow.
ch test case consists of three lines:
first line contains two integer N and M, represenöing the size of A and the size of B, respectively.
second line contains the N values of A.
third line contains the M values of B.
straints:
T< 1044
UMS5 1045
Answers
import math
def powerset(li):
ppk=[]
for x in range(1<<len(li)):
temp=[li[y] for y in range(len(li)) if x & 1<<y]
ppk.append(temp)
ppk.pop(0)
return ppk
s=int(input())
for x in range(s):
ss=list(map(int,input().split()))
n=ss[0]
m=ss[1]
N=list(map(int,input().split()))
M=list(map(int,input().split()))
result=-1
nsubs=powerset(N)
msubs=powerset(M)
for i in nsubs:
for j in msubs:
c=0
for p in i:
for q in j:
xxx=p*q
if int(round(xxx ** (1. / 3))) ** 3 == xxx:
c=c+1
if c==len(i)*len(j):
if len(i)**2+len(j)**2>result:
result=len(i)**2+len(j)**2
print(result)
Answer:
Explanation: