TWOVRIBL @ July-Cook off

Heyy, I am having a doubt in two of my submissions of the problem TWOVRIBL.

First one gives a TLE even though the answers are correct in both (verified).

In the code the only difference is using P*P and y= sqrt(P).

But I can’t get it why it causes a TLE in the first.

I am attaching the links. Can you help me out ???
First submission @TWOVRBLE Second submission@ TWOVRBLE

You aren’t updating x in the first submission in the else case.

My logic was such that if k>p then only the operation will be proceeded…else only value of p is incremented.

Can you please explain in detail…I don’t think that is the reason for getting TLE for inputs >10^7.