跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F0968. New Year and Binary Tree Paths

    ID: 974 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 10 上传者: 标签>位运算枚举组合数学动态规划数学算法思想挑战难度共享题库Codeforces英文题面题目来源题面语言

New Year and Binary Tree Paths

题目描述

G. New Year and Binary Tree Paths
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The New Year tree is an infinite perfect binary tree rooted in the node 1. Each node v has two children: nodes indexed (2·v) and (2·v+1).

Polar bears love decorating the New Year tree and Limak is no exception. As he is only a little bear, he was told to decorate only one simple path between some pair of nodes. Though he was given an opportunity to pick the pair himself! Now he wants to know the number of unordered pairs of indices (u,v) (uv), such that the sum of indices of all nodes along the simple path between u and v (including endpoints) is equal to s. Can you help him and count this value?

Input

The only line of the input contains a single integer s (1≤s≤1015).

Output

Print one integer, denoting the number of unordered pairs of nodes indices defining simple paths with the sum of indices of vertices equal to s.

Example
Input
10
Output
4
Note

In sample test, there are 4 paths with the sum of indices equal to 10:


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 411 题。保留原作者与原赛事署名。