As the question titles states, how can I efficiently find whether $d + \frac{n}{d} \equiv 0 \pmod 4$, given that $d$ divides $n$? An example would be with $n = 35$ and $d = 5$.
$5 + \frac{35}{5} = 5+7 = 12 \equiv 0 \pmod 4$, so it "passes". I tried $d + \frac{n}{d} \equiv 0 \pmod 4$, so $\frac{n}{d} \equiv -d \pmod 4$. This means that $n$ must equal $-d^{2}$ (mod 4). Can someone let me know if this is right? If not, what is a good way/are some preconditions of $d$ and $n$ so that $d + \frac{n}{d} \equiv 0 \pmod 4$.