Your task is to count for the number of ways two knights can be placed on a chessboard so that they do not attack each other.
Example:
Input: n = 8
Output:
0 6 28 96 252 550 1056 1848
Approach:
C++
#include <bits/stdc++.h>using namespace std;void twoNights(long long int k){for (long long int n = 1; n <= k; n++){long long int res = n * n * (n * n - 1) / 2;res -= 4 * (n - 1) * (n - 2);cout << res << "\n";}}int main(){long long int k = 8;twoNights(k);return 0;}
No comments:
Post a Comment