luogu#P4808. [CCC 2018] 平衡树
[CCC 2018] 平衡树
Problem Description
This problem is translated from CCC 2018 S4 “Balanced Trees”.
We define a “perfectly balanced tree” as follows:
Each perfectly balanced tree has a positive integer weight. A perfectly balanced tree with weight is a tree with only node. Otherwise, if the tree has weight , then it is a rooted tree with subtrees. All subtrees must be the same, and all of its subtrees must be exactly identical, and each subtree itself must be perfectly balanced.
In particular, the weights of all subtrees must be the same. Their weight must be . For example, if a perfectly balanced tree of weight has subtrees, then each subtree has weight , because .
Given , find the number of perfectly balanced trees with weight .
Input Format
The input contains one line with one integer .
Output Format
Output one integer, the number of perfectly balanced trees with weight .
4
3
10
13
Hint
Sample Explanation 1
The valid trees are:
- A perfectly balanced tree whose root has subtrees of weight .
- A perfectly balanced tree whose root has subtrees of weight .
- A perfectly balanced tree whose root has subtrees of weight .
Constraints:
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For all testdata, .
Translated by ChatGPT 5