We have given an integer n, we need to find the number of ways two knights can be placed on an n×n chessboard so that they do not attack each other.
I tried the simulation strategy but it is too costly as n can be of 10000. BY googling I got this formula
$ a = n * n * (n * n - 1) / 2$
$ b = 2 * (n - 2) * (2 * (n - 4) + 6)$
$ ans = a - b $
can anyone explain this formula I can't get my head through it?