Here is the link to the problem: https://icpcarchive.ecs.baylor.edu/external/74/7444.pdf
I've thought this prob for 1 day and half, all i've thought is: Find the maximum gcd of a1, a2, a3...ak(a1 + a2 + a3 + ... + ak = L) but i don't know how to solve that problem, i think that use dp but L <= 10^5, that's impossible Please, help me solve this problem!!