Editorial
Suppose tiles of length are used times. Since the two lengths alternate and both the first and last tiles have length , tiles of length are used times. Both tile lengths must be used, so .
Therefore,
Temporarily ignore the condition . Let . Then
Once with is fixed, division with remainder uniquely determines and , and therefore also . Thus, we initially have choices for .
Now remove the invalid cases.
First, consider . This happens exactly when the remainder of dividing by is zero, so it is equivalent to being a divisor of .
Second, consider . In this case,
Since ,
If divides , then is even. In the case , is odd. Therefore, these two kinds of invalid cases are disjoint.
Also, every positive divisor of except itself satisfies . If is even, then divides , corresponding to . If it is odd, it corresponds to . Hence the number of invalid choices is the number of positive divisors of , excluding itself.
Let denote the number of positive divisors of . The answer is
We can compute by testing divisors up to , giving an algorithm.
Since the answer is , it always fits in a signed 64-bit integer.
Solution written by GPT5.6