no expressed as sum of squares in n way $$50=1+49=25+25$$
$$325=1+324=36+289=100+225$$
So $50$ is the smallest number that can be represented as sum of two squares in tow ways...
$325$ is smallest number that can be expressed as sum of two squares in $3$ ways...
Is there a efficient method to find the smallest number that can be represented as sum of two squares in $n$ ways?
Link  :
http://www.cs.toronto.edu/~mackay/sumsquares.pdf‎
 A: It seems that, based on some of the plots in Mackay's report, that the probability that a number can be represented as a sum of squares in $k$ ways is asymptotic to $c^k$ for some number $0 < c < 1$. So probably your best approach is to generate sums of squares that are equal, by solving $wv = xy$ for different pairs of integers $(w,v), (x,y)$ that satisfy the constraints in MacKay's report, and then maintain a hash table that maps the two squares you get to their sum, and keep track of the number of sums of squares that map to each integer. When $\max(w,v,x,y)$ is too large, you will get that the sum of squares is large, and you can put a bound so that after you've checked $w,v,x,y$ in a certain range you can guarantee that you've found all sums of squares that add up to be $\leq N$ for a given $N$. Then just report the smallest number that can be represented as a sum of squares in $2,3,4,\ldots$ ways by checking your hash table. To speed things up, you could store the numbers that are expressible in two ways as a sum of squares in a min-heap, and similarly store numbers that are expressible in 3 ways in a min-heap, etc., and when you find that a number can be represented in a new way as a sum of squares then you remove it from its current heap and move it to the next heap. Then the top of each min-heap is the smallest number you've found which can be written as a sum-of-squares in exactly $k$ ways, and once you check $(w,v,x,y)$ large enough you can guarantee that the top of each heap contains the smallest number representable as a sum of $k$ squares, for $k$ however large you want to go.
