Number of ways two knights can be placed such that they don't attack.

Solution 1:

Note that when we have two knights threatening each other, it actually forms either a $2\times3$ or $3 \times 2$ board. And for each of $2 \times 3$ and $3 \times 2$ boards, there are $2$ ways of placing two knights so that they threaten each other. So, what we should do is to count how many $2 \times 3$ and $3 \times 2$ squares on $n\times n$ board. For general $n$, the answer is $$(n-1)(n-2)+(n-2)(n-1) = 2(n-1)(n-2)$$ And for each $2\times3$ and $3\times2$ board, there are $2$ ways of placing the knights so that they threaten each other. Therefore, in total there are $$2\cdot2(n-1)(n-2)=4(n-1)(n-2)$$ ways of placing two knights so that they threaten each other. So what you are looking for is $$\frac{n^2(n^2-1)}{2}-4(n-1)(n-2)$$ It is also worth mentioning that we are not over-counting because whenever we place two knights so that they threaten each other, either a $2 \times 3$ or $3 \times 2$ board must contain both of the knights.