Congruence condition for two to be a quadratic residue