0

[Time limit exceeded error]

How can i overcome TLE ? Its haunting me very a much !😑 P.S: ive googled but not very much clear !

15th Jan 2021, 5:13 PM
RuntimeERROR
RuntimeERROR - avatar
6 Antworten
+ 3
Netha_r2071 , i don't think that it is a complex issue or complex calculation that causes your problem. i have been run the code in a debugger. Your code is calling a function that has all expressions of that program inside. it uses a while loop, that will run as long as you NOT input "0 0". i(if input is "0 0", an if statement with a break will terminate the program regular.) in all other cases when you input something like "1 1", the code will print "BAD ...", and the LOOP EXECUTES AGAIN. in a regular IDE this is not an issue, because you are asked then to do an input again. in sololearn playground the situation is different. ALL inputs have to be given in advance like: 1 1 2 2 5 5 0 0 in this case the code will be executed as expected and terminated without exception. if you only input like 1 1, the program will be terminated with an EOFError.
16th Jan 2021, 10:20 AM
Lothar
Lothar - avatar
+ 2
Netha_r2071 , without having seen your code it is not possible to give you some help. So please put your code in playground and link it here. thanks!
15th Jan 2021, 7:31 PM
Lothar
Lothar - avatar
+ 1
Can you post your code ? So that it will be easier to understand your doubt in detail
15th Jan 2021, 5:18 PM
Atul [Inactive]
0
Atul itwas in one of my contests where limit was 2 sec and my code crossed that ,anyways i was asking in general what should be done!
15th Jan 2021, 5:22 PM
RuntimeERROR
RuntimeERROR - avatar
15th Jan 2021, 7:32 PM
RuntimeERROR
RuntimeERROR - avatar
0
no one will know what that means. if you post code probably should say what it does. sample input to use etc or no one will help u. improving code is very simple though. profile it. ok if you don't have one of those, i saw a stack overflow post that says if you run program and pause several times (after a while) and you are shown the same block of code several times that is probably your problem. in general though you gotta know about algorithms and computational complexity. as far as i can see, u are iterating through a range of elements and then taking the modulus if i give you a large prime number, then it will go the whole loop and print BAD. think for these kinds of problems you can stop after sqrt(n) since you will know after that if you can divide it by another number where n is your input (this is because you are looking for common multiples - what divides 4=2*2, what divides 81=3*27, u only need one) computational complexity-wise, your loop will reduce from O(n) to O(sqrt(n))
15th Jan 2021, 10:49 PM
Javadev