<s>[INST] Divisibility of $2^n-n^2$ by 7 How many positive integers $n<10^4$ are there such that $2^n - n^2$ is divisible by 7?  
 [/INST] Just write out periods:
$2^n:2,4,1,2,4,1,2,4,1,2,4,1,2,4,1,2,4,1,2,4,1,|2...$ with period $3$
$n^2:1,4,2,2,4,1,0,1,4,2,2,4,1,0,1,4,2,2,4,1,0,|1...$ with period $7$
So in every $21$ numbers there are $6$ numbers.
Now just calculate $10^4\over 21$$=476$ and since $10000$ itself is not included there are $3$ remainder left so totally $6\cdot476+1=2857$ numbers.
</s>