In this Kata, you will be given a number `n` (`n > 0`) and your task will be to return the smallest square number `N` (`N > 0`) such that `n + N` is also a perfect square. If there is no answer, return `-1` (`nil` in Clojure, `Nothing` in Haskell, `None` in Rust). 

```clojure 
solve 13 = 36
; because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49

solve 3 = 1 ; 3 + 1 = 4, a perfect square
solve 12 = 4 ; 12 + 4 = 16, a perfect square
solve 9 = 16 
solve 4 = nil
```

```csharp 
solve(13) = 36
//because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49

solve(3) = 1 // 3 + 1 = 4, a perfect square
solve(12) = 4 // 12 + 4 = 16, a perfect square
solve(9) = 16 
solve(4) = -1
```

```haskell 
solve 13 = Just 36
-- because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49

solve 3 = Just 1 -- 3 + 1 = 4, a perfect square
solve 12 = Just 4 -- 12 + 4 = 16, a perfect square
solve 9 = Just 16 
solve 4 = Nothing
```

```python
solve(13) = 36
# because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49

solve(3) = 1 # 3 + 1 = 4, a perfect square
solve(12) = 4 # 12 + 4 = 16, a perfect square
solve(9) = 16 
solve(4) = -1
```

More examples in test cases. 

Good luck!

Difficulty: introductory

Starter code:

def solve(n):
	

Solutions:
def solve(n):
    for i in range(int(n**0.5), 0, -1):
        x = n - i**2
        if x > 0 and x % (2*i) == 0:
            return ((n - i ** 2) // (2 * i)) ** 2
    return -1

def solve(n):
#Imagine a table, 1 to n on the top, and 1 to n on the side.
#The contents of the table are the difference between the columnNo.^2 minus the rowNo.^2 (positive values only)
#Therefore the row must always be smaller in value than the column number.
#The first diagonal shows values of the pattern 2*rowNo. + 1, the second 4*rowNo. + 4, the third 6*rowNo. + 9.
#Therefore let rowNo. = R, and the diagonal = D and the value in the table be n.
#n = 2*D*R - D^2
#Rerarrage to get  R = (n-(D ** 2))/(2 * D) 

    answer = -1
    for D in range(1, max(int(n ** 0.5),5)):
        R = (n-(D ** 2))/(2 * D)
        if R.is_integer() and R > 0:
            answer = R ** 2

    return answer

solve=lambda n:next((((n-x*x)//2//x)**2for x in range(int(n**.5),0,-1)if(n-x*x)%(2*x)==0<n-x*x),-1)

def solve(n):
    res = float('inf')
    for x in range(1, int(n**0.5)+1):
        y, r = divmod(n, x)
        if not (r or x == y) and y-x & 1 ^ 1:
            res = min(res, y-x >> 1)
    return -1 if res == float('inf') else res**2

import math
def solve(n):
    for i in range(math.ceil(n**0.5)-1, 0, -1):
        if n%i == 0:
            bma = n/i - i
            if bma%2 == 0:
                return (bma/2)**2
    return -1

def solve(n): 
    X = 1e9
    for i in range(1, int(n**(1/2)) + 1): 
        if n % i == 0: 
            a = i 
            b = n // i    
            if b - a != 0 and (b - a) % 2 == 0: 
                 X = min(X, (b - a) // 2) 
    return(X * X if X != 1e9 else -1) 

def solve(d):
    if (d%4) != 2:
        for i in range(1,(d//2)+1):
            if (d+(i*i))**.5 % 1 == 0:
                return i*i
    return -1

def solve(n):
    if (n%2 == 0 and n%4 != 0) or n == 1 or n == 4:
        return -1
    for i in range(n-1):
        if ((n + (i+1)**2)**0.5)%1 == 0:
            return (i+1)**2


#let N be a^2
#n + N = M^2 (our answer)
#n + a^2 = m^2
#stuff in slimesquad chat to read from
import math
def solve(n):
    d = math.ceil(math.sqrt(n)) - 1 #find the last biggest root we can use thats not the same number
    #now we need to go backwards because it cant be bigger than root N
    #we need to find a pair of factors for n (which is equal to x*y in discord) that are the same even and odd
    #or else A wouldnt be even
    print(d)
    for a in range(d, 0, -1):#the last argument is to go backwards
    #if we have Found a factor of N that is below the root(N) (finding the closest factors)
    #We go down from Root (N) because the further we go down, the more further apart the factors are
    #and if the difference gets bigger, we will have a bigger square number because the number
    #we need to find is the difference divided by 2
        if (n % a == 0):
        #then find the second factor it could be
        #we can do this easily
            e = (n/a)  - a
            print((a,e))
            if e % 2 == 0:
                p = e / 2
                return p*p
    return -1