Continuing the discussion from MXMLCM - Editorial:
Solution link:
I have followed instructions as mentioned in editorial but still I am getting TLE on the last subtasks
Any help will be appreciated

I tried optimizing code and got best AC 0.6 seconds still was not able to pass any test case for subtask 2 .I do not do competitive programming in python and it takes 5 times more time than in C++ to execute a code ,however there are multipliers in time limits.And seeing your code I wanted to tell you that the python variable in range is not dynamic .Meaning if you have a for loop as :

num = 16
for x in range(1, int(math.sqrt(num))) :
num = 0
#Both above lines are inside for loop

It seems the loop will execute only one time but it doesn’t happen.Once range has got upper limit as 4 ,it will execute for x = 1,2,3 ,irrespective of the value of num after beginning of loop.
You can see the following link :(I wrote two loops for understanding ,you can refer to it )

Happy Coding :slight_smile:

Thanks a lot for such a nice explanation. :slightly_smiling_face:
I should have used while loop which is dynamic rather than for (in range ) as you pointed . Now it has passed all test cases. Once again thanks for pointing out this.
Can you please tell me how you come up with that this might be the problem with my code as I spent a lot of time debugging it but was unable to?

Oh great it passed !! :slight_smile:
At the beginning its difficult to debug problems but it will become easier when you will practice more and more .Practicing not only means just solving the problems ,it also requires make sure that you go through the editorials or alternative solutions of the problem you are able to do or not able to do .

Thanks a lot :slightly_smiling_face: )