Pari/GP, 42 bytes
Using the built-in qfrep.
n->1+2*vecsum(Vec(qfrep([2,1;1,2],n^2,1)))
qfrep(q,B,{flag=0}): vector of (half) the number of vectors of norms from 1 to B for the integral and definite quadratic form q. If flag is 1, count vectors of even norm from 1 to 2B.
Pari/GP, 42 bytes
Using the built-in qfrep.
n->1+2*vecsum(Vec(qfrep([2,1;1,2],n^2,1)))
qfrep(q,B,{flag=0}): vector of (half) the number of vectors of norms from 1 to B for the integral and definite quadratic form q. If flag is 1, count vectors of even norm from 1 to 2B.