Nos of possibilities of $x^2+y^2=d^2$ I was trying to find the numbers of possibilities of $x^2+y^2$ that are not perfect squares for $0\le x\le m$ and $0\le y\le n$ and $x+y>0$. 
I think if we calculate the numbers of possibilities of $x^2+y^2=d^2$, it will do it. Any formulas or even an algorithm?
 A: We give a count of the number of representations of an integer as a sum of two squares, if there are no size restrictions. This does not answer the question, but is in response to a request from the OP. 
Let $n$ be a positive integer, and let 
$$n=2^ap_1^{a_1}\cdots p_s^{a^s} q_1^{b_1} \cdots q_t^{b_t},$$
where the $p_i$ are distinct primes of the form $4k+1$, and the $q_j$ are distinct primes of the form $4k+3$. 
If at least one of the $b_j$ is odd, then $n$ has no representations as a sum of the squares of two integers.
If all the $b_j$ are even, then $n$ has $N(n)$ representations as the sum of the squares of two integers (positive, negative, or $0$), where
$$N(n)=4(a_1+1)(a_2+1)\cdots(a_s+1).$$
We may instead be interested in the number of essentially distinct representations, where for example the representations $2^2+3^2=13$, $3^2+2^2=13$, $(-2)^2+3^2=13$, and so on are considered to be "the same." Note that if $n=k^2$, the representation $n=k^2+0^2$ is included in the count. 
If $8$ divides $N(n)$, then there are exactly $\dfrac{N(n)}{8}$ essentially distinct representations of $n$ as a sum of two squares.
If $8$ does not divide $N(n)$, then there are $\dfrac{N(n)+4}{8}$ essentially distinct representations of $n$ as a sum of two squares.
Now let $n=d^2$. If we know the prime power factorization of $d$, we can write down the prime power factorization of $d^2$, and then use the above formulas. 
