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
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
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=((e-s)/lcm)+1 and stored in c) by e then I subtracted c from total no. of soldiers in kings army.@karun369
LCM is not O(1), especially if your numbers are having like 1000+ digits. Try breaking after your LCM reaches the upper limit.