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?

• What do you know about Pythagorean Triples? – Brevan Ellefsen Mar 25 '17 at 3:09
• The possible final digits can only be those digits. – Thomas Andrews Mar 25 '17 at 3:09
• Pythagorean Triples are integers $a,b,c$ in the form $a^2$+$b^2$=$c^2$ – jonyoung2002 Mar 25 '17 at 3:13
• OK. Looked it up. So what I would do is first write 2017 as the sum as 2 squares (9,44) and substitute those values for m and n. Then I would do $44^2$-$9^2$=a and $44$*$9$*2=b. – jonyoung2002 Mar 25 '17 at 3:20
• Got it! Thanks! – jonyoung2002 Mar 25 '17 at 3:21

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.

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$.