Run a loop from max element to 1 to find subsets with all gcds
for i in range ( arrMax , 0 , - 1 ) : NEW_LINE INDENT sub = 0 NEW_LINE add = 0 NEW_LINE if i in freq : NEW_LINE INDENT add = freq [ i ] NEW_LINE DEDENT j = 2 NEW_LINE DEDENT