How many positive integers less than or equal to $2019$ could be written as sum of two squares? When I was reading my school magazine, I found some hard problems in the Math Corner page. I can't solve two of the questions. Here is one of them

How many positive integers less than or equal to $2019$ could be written as sum of two squares?

Can someone help me solve this?
Click here to go to the other question.
 A: This is not an efficient method but since you mentioned school magazine I think this approach makes sense.We want $a^2+b^2\leq 2019$ . We know that $45^2=2025$ thus both$a,b\in[1,44]$ Now let's assume $b=1$ thus the range of values for $a\in [1,44]$ , now let $b=2$ again we get $a\in[1,44]$ similarly for $b=3,4,5,...,31$ why till $31?$ we let $a=b$ thus we need $2a^2\leq 2019$ and max value occurs at $31$ . Now note the symmetry .So you can start from $b=44$ and go till $31$ if you want to reduce the calculation. Thus $\text{total number of ways =2(total number of ways to have a st b\in[1,31])+1}$. This is a very crude method but I think this can be one of the ways at school level.
A: Brute force method consists in creating a 45x45 matrix of $(i^2+j^2)$, and to remove duplicates. It gives 623 positive integers.
Using Fermat's theorem on sums of two squares (https://en.wikipedia.org/wiki/Fermat%27s_theorem_on_sums_of_two_squares)
might be less advantageous (and out of scope anyway). Indeed you have more primes that squares between $0$ and $2019$.
A: An asymptotic formula for the general problem (though not school level). 
Fermat's theorem on primes (pointed in one of the answers)  is not sufficient to answer this question as it deals with only primes which can be written as the sum of two primes. What we need are the general conditions under which an integer can be written as the sum of two squares

An integer greater than one can be written as a sum of two squares if
  and only if its prime decomposition contains no prime congruent to
  $3{\pmod {4}}$ raised to an odd power.

So the only theoretical way to check this to decompose each number into its prime factors and checking its multiplicity. But this is not necessarily more efficient than a brute force approach. None the less when we compute the asymptotics, we

Ramanujan- Landau Theorem: The number of integers $\le x$ which can be
  expressed as the sum of two square is asymptotic to  $$
 N(x) \sim \frac{Kx}{\sqrt{\log x}}\Big(1 + \frac{C}{\log x}\Big) $$ where $K \approx 0.7642236$ and $C \approx 0.58194865$ are constants.

For $x = 2019$, the formula gives $N(2019) \approx 602$ which not too far from the actual value of $595$.
