I am doing coding challenge named Integers: Recreation One in Codewars.

Challenge => Given two integers m, n (1 <= m <= n) we want to find all integers between m and n whose sum of squared divisors is itself a square.

```
def list_squared(m, n):
lst = list()
for num in range(m, n+1):
total= 0
for i in range(1, num//2 +1):
if num % i == 0:
total += i**2
total += num**2
if (total**(1/2)) % 1 == 0:
lst.append([num, total])
return lst
```

My code works for sample tests but when I try to submit it, it is giving me " Execution Timed Out " error. I think I have to make this more efficent but don't know how to do it. How can I make the code more efficent?

An implementation of the

`sqrt`

idea:It seems to work. A couple things which may or may not make sense:

`**(1/2)`

or`math.sqrt`

performs better, it could be checked. However I feel`sqrt`

is more readable. Of course if you are not allowed to use the math library, stick with`**`

`x*x`

is faster than`x**2`

, it could be checked too`divmod`

(so`q*q`

replaces`(num/i)*(num/i)`

, or`(num/i)**2`

)In reality these details probably do not matter at all, shortening the inner loop should be the main trick.

@H.E.K.: you "felt" that the loop can be shortened somehow, via the

`/2`

thing, but in reality it has to be square root.If

`i`

is divisor of`num`

,`num/i`

is also a divisor of`num`

. And if`i`

starts increasing from`1`

,`num/i`

starts decreasing from`num/1`

(so from`num`

itself). As time passes, they will meet somewhere, and that is`sqrt(num)`

. Increasing`i`

above`sqrt(num)`

ends up with checking a divisor-pair which you have seen already. An example with 20:so the divisors are 1,20,2,10,4,5 - and we did not have to check 5...20 separately, it was enough to check

`1...4=(int)sqrt(20)`

, which is a significant gain.