Problem:
Let be the number of sequences of integers that satisfy all of the following properties:
- Each is either or a power of .
- for .
- .
Find the remainder when is divided by .
, 2021
Solutions — 2
Solution 1
Solution:
This problem can be visualized as a complete binary tree with leaves, such that each node contains the sum of its two children. Let be the number of ways to fill in a binary tree with leaves and the root having value . We want .
Since all values must be a power of , we can set up the recurrence . This is because we have three cases: either all of the can go to the left child of the root (in which case there are ways because even though there's in the new root, we can treat it as because none of the leaves will have a value of ), all of it can go to the right child of the root (another ways), or it can be split evenly ( ways).
This recursion can be shown to be by induction. Thus, our answer is which is modulo .
Solution 2
Solution:
The simple formula derived in the previous solution hints at a cute bijection. It turns out that the entire tree is determined by the set of leaf nodes that have non-zero value. You can see this is true: start with the root node, then only split the value each time if both subtrees have a non-zero leaf. The entire process is uniquely determined. Thus, the total number of ways is to the number of leaves, minus one for the case where all of the leaves have zero value.