×

Fighting Armies (ARMYFGT)

 0 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 1 accept rate: 0%

 0 bro can you explain the logic behind it @akashdeep18 answered 02 Jan, 18:49 2★karun369 1●1 accept rate: 0% 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 (02 Jan, 19:24)
 0 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 63●2 accept rate: 7% Thankyou @arvindpunk your suggestion helped got AC. (02 Jan, 20:11)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,422
×727