Codeforces Global Round 5
E
Balanced Binary Search Trees
Codeforces
2400
原题
← DF →
翻译中…

Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree.

翻译中…

The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is $0$.

翻译中…

Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices.

翻译中…

Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex $v$:

翻译中…
  • If $v$ has a left subtree whose root is $u$, then the parity of the key of $v$ is different from the parity of the key of $u$.
  • If $v$ has a right subtree whose root is $w$, then the parity of the key of $v$ is the same as the parity of the key of $w$.
翻译中…

You are given a single integer $n$. Find the number of perfectly balanced striped binary search trees with $n$ vertices that have distinct integer keys between $1$ and $n$, inclusive. Output this number modulo $998\,244\,353$.

翻译中…

Input

翻译中…

The only line contains a single integer $n$ ($1 \le n \le 10^6$), denoting the required number of vertices.

翻译中…

Output

翻译中…

Output the number of perfectly balanced striped binary search trees with $n$ vertices and distinct integer keys between $1$ and $n$, inclusive, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first example, this is the only tree that satisfies the conditions: image

翻译中…

In the second example, here are various trees that don't satisfy some condition: image

翻译中…

样例

Input #1
4
Output #1
1
InputCopy OutputCopy
Input #2
3
Output #2
0
InputCopy OutputCopy
题目信息
题号
1237E
时间限制
3 s
内存限制
512 MB
标签
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。