RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
R03548

S4. Balanced Trees

Unrated 레이팅 미적용
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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\ge 2\), then the tree consists of a root node with branches to \(k\) subtrees, such that \(2\le k \le 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 \le 8\).

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

제약

\(w\ge 2\)
\(2\le k \le w\)
\((1\le N\le 10^9)\)
\(N\le 1000\)
\(N\le 50000\)
\(N\le 10^6\)

입력 형식

The input will be a single line containing the integer \(N\) \((1\le N\le 10^9)\).

For \(5\) of the \(15\) marks available, \(N\le 1000\).

For an additional \(2\) of the \(15\) marks available, \(N\le 50000\).

For an additional \(2\) of the \(15\) marks available, \(N\le 10^6\).

출력 형식

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

예제 1
입력
4
출력
3
설명

One tree has a root with four subtrees of weight 1; a second tree has a root with two subtrees of weight 2; the third tree has a root with three subtrees of weight 1.

예제 2
입력
10
출력
13
문제 정보

생성자가 기록되지 않았습니다.

출처 CCC 2018 Senior

평가 및 의견

S4. Balanced Trees

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

S4. Balanced Trees

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8