I am unable to solve ARMYFGT. Complexity of my program is as expected but It is throwing TLE. Please, Someone help me out. Problem Link: https://www.codechef.com/problems/ARMYFGT Solution Link: https://www.codechef.com/viewsolution/22155263 asked 02 Jan, 16:59

bro can you explain the logic behind it @akashdeep18 answered 02 Jan, 18:49
I first calculated the lcm of all the values in the rebel army, then i tried to find out the first multiple of lcm in given range of kings army(stored it in s) and then the final multiple of lcm(stored it in e), and then I found total multiples of the lcm in given range(by using c=((es)/lcm)+1 and stored in c) by e then I subtracted c from total no. of soldiers in kings army.@karun369
(02 Jan, 19:24)

LCM is not O(1), especially if your numbers are having like 1000+ digits. Try breaking after your LCM reaches the upper limit. answered 02 Jan, 20:03
Thankyou @arvindpunk your suggestion helped got AC.
(02 Jan, 20:11)
