TLE on problem 'K2' - Palindromic Numbers

Here’s my code to the problem K2-Palindromic Numbers which is getting a TLE.

I took help from here to write the algorithm but it isn’t fitting inside the 3-sec limit.

What changes do I need to make?

View code in submitted section of problem or see the code below.

}

more links info:

https://speakerdeck.com/zoraya
https://www.sparkfun.com/users/762476
http://www.broadjam.com/zorayax
http://resource.bdonline.co.uk/users/zoraya
http://forums.cambridgesoft.com/messageview.aspx?catid=43&threadid=3305&enterthread=y
http://forums.cambridgesoft.com/messageview.aspx?catid=43&threadid=3306&enterthread=y
http://forums.cambridgesoft.com/messageview.aspx?catid=43&threadid=3307&enterthread=y
http://certo-oita.from.tv/userinfo.php?uid=1046703
http://info.hti-systems.com/xwiki/bin/view/XWiki/zoraya
http://zoraya.iwopop.com/

Hi aalok_sathe,

you are getting TLE due to for loop of low base function because-

let input number is 10^10 then you called function and this value is copied into z then z is not less than 6 ( of course ) hence value if lim is (10^10)/2 i.e 5 * 10^9 and now you are iterating from b=2 to 5 * 10^9 which is large and also number of test cases are 10^3 hence total complexity is 5*10^12 which is much large to run within 3 sec. and also there are some bug in your code but first fix it.

try to optimize you algorithm and replace this loop.
at last you wrote printf(“0”) here you will never get input zero so no need to write it.

go through this :slight_smile:

1 Like
//