study math. code becomes shorter :P

logic is very simple
for knights to threaten, they have to be L shape => 2x3 or 3x2 box
how many 2x3 boxes in NxN? (n-2).(n-1)
and 3x2 is also (n-2).(n-1)
and two knights are there so total is
4.(n-2).(n-1)
Safe places = total ways - threaten
= n^2(n^2-1)/2 - 4.(n-2).(n-1)
Missing some Tweet in this thread? You can try to Update