Find all integer values: $a^2+b^2=2017^2$ I read something about how the possible digits of any square number is $0,1,4,5,6,9$ and that I could bash it out, but then that would take a lot of time. Is there any other way to to this problem?
 A: By combining Fermat's theorem on sums of squares and the irreducible elements in the Gaussian integers $\mathbb{Z}[i]$ one can find the number of representations of an integer n(not necessarily a square) when in n's prime factorization all primes are congruent to 1 mod 4. We have the following method which gives the number of the representations and how to find them. Let:
$$n=p_{1}^{a_{1}}...p_{n}^{a_{n}}$$
Such that all $p_{k}$ are congruent to 1 mod 4. There are exactly $4(a_{1}+1)...(a_{n}+1)$ representations of n as a sum of squares. And these can be found by factorizing $p_{k}$ in the Gaussian integers as $p_{k}=(a+bi)(a-bi)$ and multiplying any combination made by taking $a_{n}$ guys from each $p_{k}$'s factorization.
For your specific problem, since 2017 is a prime congruent to 1 mod 4 by the formula above it can be written in 4x3=12 ways. 2017's factorization is:
$$2017=(44+9i)(44-9i)$$
hence
$$2017^2=(44+9i)^2(44-9i)^2$$
by picking any two guys(we use two picks since the others are the same) from the above representation you get all the answers except for changing signs and summands:
$$1855+792i=(44+9i)(44+9i)$$ 
$$2017+(0)i=(44+9i)(44-9i)$$ 
So 6 of 12 solutions with all possible choices of signs are $2017^2=(\pm1855)^2+(\mp792)^2=(\pm2017)^2+0^2$. The other 6 solutions are made by changing the order of summands.
Note factorizing 2017 in the Gaussian integers is the same as finding the only two numbers such that  $2017=a^2+b^2=44^{2}+9^{2}$ which still takes time since 2017 is a large prime, but is still easier than doing the same directly for 2017^2. Generally this method works better for small primes in factorizations.
A: All Pythagorean triples $(a,b,c)$, $a^{2}+b^{2}=c^{2}$, satisfy the formulas 
\begin{equation*}
a=k(m^{2}-n^{2}),\quad b=2kmn,\quad c=k(m^{2}+n^{2}),\qquad m>n> 0,\quad k> 0.
\end{equation*}
Since $c=2017=44^{2}+9^{2}$(see this answer), $k=1$.
Then $m=44,n=9$, and
\begin{eqnarray*}
a &=&m^{2}-n^{2}=44^{2}-9^{2}= 1855,
\\
b &=&2mn= 2(44)(9)= 792.
\end{eqnarray*}
The other solutions are found by allowing negative values or  swapping $ a $ with $ b $. So  $ a=\pm 1855, b=\pm 792$, $ a=\pm 792, b=\pm1855 $.
A: We can find a triple for any value of $C$, if it exists for a primitive, a double of a primitive, or a perfect square times a primitive by solving $C$ for $n$ and using a finite search of $m$ values to see which, if any, yield an integer $n$.
Given $C= m^2+n^2,\space n=\sqrt{C-m^2}$ where $\biggl\lceil\sqrt{\frac{C}{2}}\space\space\biggr\rceil \le m\le\bigl\lfloor\sqrt{C}\bigr\rfloor$.
For example, if $C=2017,$
$$n=\sqrt{2017-m^2}\text{ where } \biggl\lceil\sqrt{\frac{2017}{2}}\space\space\biggr\rceil=32 \le m\le\bigl\lfloor\sqrt{2017}\bigr\rfloor=44$$
In testing $32\le m \le 44$, we find that only $m=44$ yields an integer $(9)$.
$$f(44,9)=(1855,792,2017)$$
A: Another way of doing this is to write a computer program:
Python Program
c2 = 2017 * 2017
a = 1
b = 2017
while 1:
    if a == b:
        break
    a2 = a * a
    b2 = b * b
    d2 = a2 + b2
    if d2 > c2:
        b = b - 1
        continue
    if d2 < c2:
        a = a + 1
        continue
    if d2 == c2:
        print('success',a,b)
        a = a + 1
        b = 2017
print('exit',a,b)

OUTPUT
success 792 1855
exit 1426 1426

