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 11 is a tree with only 11 node. Otherwise, if the tree has weight w(w2)w(w\ge2), then it is a rooted tree with k(2kw)k(2\le k\le w) subtrees. All kk subtrees must be the same, and all of its kk subtrees must be exactly identical, and each subtree itself must be perfectly balanced.

In particular, the weights of all kk subtrees must be the same. Their weight must be wk\left\lfloor\frac{w}{k}\right\rfloor. For example, if a perfectly balanced tree of weight 88 has 33 subtrees, then each subtree has weight 22, because 2+2+2=682+2+2=6\le8.

Given NN, find the number of perfectly balanced trees with weight NN.

Input Format

The input contains one line with one integer NN.

Output Format

Output one integer, the number of perfectly balanced trees with weight NN.

4
3
10
13

Hint

Sample Explanation 1

The valid trees are:

  • A perfectly balanced tree whose root has 44 subtrees of weight 11.
  • A perfectly balanced tree whose root has 22 subtrees of weight 22.
  • A perfectly balanced tree whose root has 33 subtrees of weight 11.

Constraints:

For 33%33\% of the testdata, N1000N\le1000.
For another 13%13\% of the testdata, N5×104N\le5\times 10^4.
For another 13%13\% of the testdata, N106N\le10^6.
For all testdata, 1N1091\le N\le10^9.

Translated by ChatGPT 5