Time Limit Exceed

I am getting time limit exceed for two questions. what things increase the time nd how can it be resolved?

hey @mehta.rashita18, time complexity of code increases when your code takes more time than the judge system allows, in your code the limits of a and b is more, use pen and paper and try to figure out what is the maximum possible value of a and b.

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

this is my code…please help me out…what should i do now… it is giving correct output, but taking too much time

N=int(input())

l=[int(input()) for i in range(N)]

for no in l:

ans=[]

for b in range(0,int((no)**(1/2)) +1):

    s=[(a,b) for a in range(0,b+1) if (a**2 + b**2 ==no)]

    if len(s)==0:

        pass

    else:

        ans.append((*s))

print((*ans))

Hey @mehta.rashita18, this is the solution code, try to figure out your self now, how we managed to reduce the time complexity.

import math
n = int(input())
for i in range(n):
    inp = int(input())
    for j in range(int(math.sqrt(inp)) + 1):
        for k in range(j, int(math.sqrt(inp)) + 1):
            if(j ** 2 + k ** 2 == inp):
                print('(' + str(j) + ',' + str(k) + ')', end = " ")
    print() 

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.