#P6184. Fence Board Cutting

    ID: 19404 Type: Default 1000ms 256MiB

Fence Board Cutting

Fence Board Cutting

You are given a wooden board of total length n (an integer). You need to cut this board into 4 pieces (the cuts split the board into 4 positive integer lengths) such that these pieces can form a rectangular fence. A rectangular fence is formed when the four sides can be grouped into two pairs of equal lengths (note that a square is a special rectangle). In other words, the four pieces (when rearranged arbitrarily) should consist of two pieces of length p and two pieces of length q, where p and q are positive integers and the total length satisfies

$2p + 2q = n$

The area of the fenced region must be positive (p > 0 and q > 0). Do not worry about symmetry or eliminating duplicate configurations up to rotation/reflection – simply count the number of distinct cutting methods (ordered quadruples) that meet the criteria. It is guaranteed that the final count can be stored in a 32-bit integer.

Note:

  • If n is odd, no valid cutting method exists. In such a case, output 0.
  • When n is even, let $S=\frac{n}{2}$. We want to find all pairs of positive integers $(p,q)$ such that $p+q=S$. Since the pieces, when rearranged, must appear as two p's and two q's, and order matters (that is, a cutting method is an ordered sequence of 4 pieces), each unordered pair contributes as follows:
    • If $p \neq q$, there are $\frac{4!}{2!2!} = 6$ distinct ordered sequences.
    • If $p = q$ (i.e. a square, which is allowed), there is exactly 1 distinct sequence.
  • For calculating the result, iterate over all integers p from 1 to $\lfloor \frac{S}{2} \rfloor$. For each p, let q be $S-p$. If $p < q$, add 6 to the result; if $p = q$, add 1.

inputFormat

The input consists of a single line containing an integer n ($1 \leq n \leq 10^9$) representing the total length of the wooden board.

outputFormat

Output a single integer – the number of distinct cutting methods to obtain four pieces that can form a rectangular fence.

sample

6
6