How to find the closest number to 100,000 and less than 100,000 which is a sum of two squares?

How to find the closest number to 100,000 and less than 100,000 which is a sum of two squares?

Maybe it is possible to find how many sum of square numbers are between 10,000 and 100,000? Are there few?

I know that $(a^2 + b^2)(c^2 + d^2) = (ac + bd)^2 + (ad - bc)^2$ . Or there is some criteria for knowing which number is a sum of squares in How to determine whether a number can be written as a sum of two squares? But, this could be used, I think, when I already have a number to test (or few numbers to test). I would like to avoid spending hours using trial an error on every number less than 100,000 please.

• Do you mean how many numbers are the sum of two squares? Every number is a sum of four squares. – gammatester Jun 3 '18 at 22:21
• yes, I meant maybe the problem gets solved, by first finding out how many numbers that are the sum of two squares are between 10,000 and 100,000 – Trux Jun 3 '18 at 23:02
• Well you can always to $\lfloor \sqrt{100,000}\rfloor=316$ and $100,000 - 316^2 = 144$ and $\lfloor \sqrt{144-1}\rfloor = 11$ so $316^2 + 11^2 = 99977$ is pretty darned close – fleablood Jun 3 '18 at 23:09

We have $$99997=19^2\cdot 277.$$ Here the prime $277\equiv1\pmod4$.
$271\mid99999$, $49999$ is a prime.
• This might be more convincing if you (a) showed the two squares and (b) also considered $99999$ (easy) and $99998$ (not difficult) – Henry Jun 3 '18 at 22:22
• $99999\equiv3\pmod4$ so we don't need to factor. I'm sure this is what @Henry had in mind. – Jyrki Lahtonen Jun 3 '18 at 22:24