^{2}- Dy

^{2}= 1, you can get to some really cool equations using elementary methods, valid for the special cases x = 1 or -1 mod D.

Using those equations, you can get a result involving a sum, which is x+y, and squares:

x+y = n

^{2}+ (D-1)m

^{2}

Or:

2(x+y) = n

^{2}+ (D-1)m

^{2}

for some integers n and m.

I've recently explained in a post how to calculate n and m when you know x and y.

James Harris