Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
We can select an odd number of <code>1</code>’s.
Put all the values into a HashSet. We can start from each <code>x > 1</code> as the smallest chosen value and we can find the longest subset by checking the new values (which are the square of the previous value) in the set by brute force.
Note when <code>x > 1</code>, <code>x<sup>2</sup></code>, <code>x<sup>4</sup></code>, <code>x<sup>8</sup></code>, … increases very fast, the longest subset with smallest value x cannot be very long. (The length is <code>O(log(log(10<sup>9</sup>)))</code>.
Hence we can directly check all lengths less than <code>10</code> for all values of <code>x</code>.