#P4388. Unique Scarecrow Arrangements
Unique Scarecrow Arrangements
Unique Scarecrow Arrangements
Every day, Princess Fu arranges scarecrows to form an R × C rectangle, placing one scarecrow in each cell. She then stands at the top-left corner and shoots an arrow towards the bottom-right corner. The arrow pierces through all the scarecrows along its path, and each scarecrow in a cell that the arrow passes through is destroyed. Since any path from the top-left to the bottom-right in an R × C rectangle involves exactly R + C - 1
cells, the arrow always destroys exactly R + C - 1
scarecrows.
To save money, the princess decides to arrange the scarecrows so that exactly N
scarecrows are destroyed, i.e.,
Since both R and C are positive integers, the equation becomes R + C = N + 1. Without considering rotations, there are N
possible pairs (R, C) (with R ranging from 1 to N
and C = N + 1 - R). However, the rectangle can be rotated, meaning that an R × C rectangle is equivalent to a C × R rectangle. Thus, we only count distinct arrangements up to rotation.
Your task is to compute the number of distinct scarecrow arrangements the princess can choose, given that the arrangement must satisfy:
In simpler terms, if we list all pairs (R, C) such that R + C = N + 1 and consider (R, C) equivalent to (C, R), the answer is:
- If
N
is odd, then the number of unique arrangements is \(\frac{N+1}{2}\). - If
N
is even, then the number of unique arrangements is \(\frac{N}{2}\).
For example:
- When
N = 3
: The pairs satisfyingR + C = 4
are (1,3), (2,2), (3,1). Considering rotation, (1,3) and (3,1) are equivalent, so the answer is 2. - When
N = 4
: The pairs satisfyingR + C = 5
are (1,4), (2,3), (3,2), (4,1). Here (1,4) and (4,1) form one equivalent class and (2,3) and (3,2) form another, so the answer is 2.
inputFormat
The input consists of a single integer N
(N ≥ 1
) on one line, representing the number of scarecrows destroyed by the arrow.
outputFormat
Output a single integer representing the number of distinct scarecrow arrangements (up to rotation) that satisfy the condition R + C - 1 = N
.
sample
1
1