You are not logged in. Please login at www.codechef.com 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: https://www.codechef.com/problems/ARMYFGT

Solution Link: https://www.codechef.com/viewsolution/22155263

asked 02 Jan, 16:59

akashdeep18's gravatar image

4★akashdeep18
1
accept rate: 0%


bro can you explain the logic behind it @akashdeep18

link

answered 02 Jan, 18:49

karun369's gravatar image

2★karun369
11
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.

link

answered 02 Jan, 20:03

arvindpunk's gravatar image

3★arvindpunk
632
accept rate: 7%

Thankyou @arvindpunk your suggestion helped got AC.

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

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×1,422
×727

question asked: 02 Jan, 16:59

question was seen: 127 times

last updated: 02 Jan, 20:11