diff options
-rw-r--r-- | introductory_problems/readme.md | 7 | ||||
-rw-r--r-- | introductory_problems/two_knights.cpp | 13 |
2 files changed, 20 insertions, 0 deletions
diff --git a/introductory_problems/readme.md b/introductory_problems/readme.md index 80fb417..0b39d4d 100644 --- a/introductory_problems/readme.md +++ b/introductory_problems/readme.md @@ -41,3 +41,10 @@ A number spiral is an infinite grid whose upper-left square has number 1. Your t **Input**: The first imput line contains an integer `t`: the number of tests. After this, there are `t` lines, each containing integers `y` and `x`. (Example: 3`\n`2 3`\n`1 1`\n`4 2) **Output**: For each test, print the number in row `y` and column `x`. (Example: 8 1 15) + +### Two Knights +Your task is to count for `k = 1, 2, ..., n` the number of ways two knights can be placed on a `k * k` chessboard so that they do not attack eachother. + +**Input**: The only input line contains an integer `n`. (Example: 8) + +**Output**: Print `n` integers: the results. (Example: 0 6 28 96 252 550 1056 1848) diff --git a/introductory_problems/two_knights.cpp b/introductory_problems/two_knights.cpp new file mode 100644 index 0000000..60933bc --- /dev/null +++ b/introductory_problems/two_knights.cpp @@ -0,0 +1,13 @@ +// 1072. Two Knights +#include <bits/stdc++.h> +using namespace std; + +int main() { + static int n; + scanf("%d", &n); + for (int i = 1; i <= n; i++) { + long long cnt = 1LL + (i - 1) * (i - 2) / 2; + cnt = cnt * (i - 1) * (i + 4); + printf("%lld\n", cnt); + } +} |