Cubical subsets

I am trying to solve this problem can anyone please help me how to approach this problem.

The Problem is :
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 in A’ and each element in B’, a*b is a perfect cube.
3.|A’|^2 + |B’|^2 is maximised

Example Input:
A=2,16,5
B=4,4

Output:
8

3 Likes