Integral points on a circle Given radius $r$ which is an integer and center $(0,0)$, find the number of integral points on the circumference of the circle.
 A: You are looking for solutions to $m^2 + n^2 = r^2$ for a given $r$.  Clearly $(\pm r, 0), (0, \pm r)$ are four solutions. For others, this is equivalent to finding Pythagorean triples with the same hypotenuse.  You should be able to find a lot of references on this online.
In fact you can derive that, if the prime factorisation of $r = 2^a \prod p_i^{b_i} \prod q_j^{c_j}$ where $p_i \equiv 1\pmod 4$ and $q_i \equiv 3 \pmod 4$, then $f(r) =\dfrac{1}{2}\left(\prod (2b_i + 1) - 1 \right)$ is the number of such triplets.
Each such triple has corresponding solutions in the other three quadrants, so in total we have $4f(r)+4$ integer points on the circle.
A: Hint: hunt for Pythagorean triangles.
A: Let $$R^2= a^2 +b^2$$   
Then the Number of integral points is the number of integral solutions for $(a,b)$   
For example if $R=5$
Then $$(a,b)=(0,±5) ,(±5,0), (±3,±4)  $$ 
Hence number of points are 8.  
A Simple Algorithm for this is:   
for(i=0,i<=R;i++)   
{   
    for(j=0;j<=R;j++)
    {
        if(R*R==i*i+j*j)
         count++;
    }
}

This has 10^12 computations if R=10^6
Rather than this an Optimised approach is:
for(i=0,i<=R;i++)
{   
    if(sqrt(R*R-i*i) is an integer)
     count++;   
}

This has 10^6 computations if R=10^6 which takes only 0.1 seconds on an ordinary machine. 
You can check this link for checking if a float is an integer.   
