Balanced Trees

무게 N인 완전 균형 트리의 개수를 구한다. 각 내부 노드는 k개의 동일한 부분트리를 가지며, 부분트리 무게는 k배 합이 부모 무게 이하가 되는 최댓값으로 정해진다. (N ≤ 10^9)

어려움8동적 계획법정수론수학DFS아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Trees have many fascinating properties. While this is primarily true for trees in nature, the concept of trees in math and computer science is also interesting. A particular kind of tree, a perfectly balanced tree, is defined as follows.

Every perfectly balanced tree has a positive integer weight. A perfectly balanced tree of weight 1 always consists of a single node. Otherwise, if the weight of a perfectly balanced tree is w and w ≥ 2, then the tree consists of a root node with branches to k subtrees, such that 2 ≤ k ≤ w. In this case, all k subtrees must be completely identical, and be perfectly balanced themselves.

In particular, all k subtrees must have the same weight. This common weight must be the maximum integer value such that the sum of the weights of all k subtrees does not exceed w, the weight of the overall tree. For example, if a perfectly balanced tree of weight 8 has 3 subtrees, then each subtree would have weight 2, since 2 + 2 + 2 = 6 ≤ 8.

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

입력

The input will be a single line containing the integer N (1 ≤ N ≤ 109).

출력

Output a single integer, the number of perfectly balanced trees with weight N.