You are not logged in. Please login at to post your questions!


Fighting Armies (ARMYFGT)

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:

Solution Link:

asked 02 Jan, 16:59

akashdeep18's gravatar image

accept rate: 0%

bro can you explain the logic behind it @akashdeep18


answered 02 Jan, 18:49

karun369's gravatar image

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) akashdeep184★

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

arvindpunk's gravatar image

accept rate: 7%

Thankyou @arvindpunk your suggestion helped got AC.

(02 Jan, 20:11) akashdeep184★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • 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:


question asked: 02 Jan, 16:59

question was seen: 127 times

last updated: 02 Jan, 20:11