ALTLG - Editorial

I found a much simpler solution to this problem, which I described here. It requires only simple logic, sorting, and dynamic programming. There is no need for segment trees, or splitting into prime factors. See ALTLG - Editorial (Unofficial)