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.

  • $\begingroup$ Do you mean how many numbers are the sum of two squares? Every number is a sum of four squares. $\endgroup$ Jun 3, 2018 at 22:21
  • $\begingroup$ 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 $\endgroup$
    – Trux
    Jun 3, 2018 at 23:02
  • 2
    $\begingroup$ 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 $\endgroup$
    – fleablood
    Jun 3, 2018 at 23:09

1 Answer 1


We have $$99997=19^2\cdot 277.$$ Here the prime $277\equiv1\pmod4$.

$271\mid99999$, $49999$ is a prime.

  • $\begingroup$ This might be more convincing if you (a) showed the two squares and (b) also considered $99999$ (easy) and $99998$ (not difficult) $\endgroup$
    – Henry
    Jun 3, 2018 at 22:22
  • 2
    $\begingroup$ This is really a mindless game IMHO. Just factoring the candidates. $\endgroup$ Jun 3, 2018 at 22:23
  • 1
    $\begingroup$ $99999\equiv3\pmod4$ so we don't need to factor. I'm sure this is what @Henry had in mind. $\endgroup$ Jun 3, 2018 at 22:24
  • 1
    $\begingroup$ Anyway, it's 1.30 am here. I'm not firing with all cylinders. G'night. $\endgroup$ Jun 3, 2018 at 22:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .