

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
とある世界では、今日はクリスマスです。
高羽氏のパーティで、彼は多次元バーガーを作ることにしました。レベル バーガー ( は 以上の整数) とは次のようなものです。
- レベル バーガーとは、パティ 枚である。
- レベル バーガー とは、バン 枚、レベル バーガー、パティ 枚、レベル バーガー、バン 枚、をこの順に下から積み重ねたものである。
例えば、パティを P
、バンを B
で表すと、レベル バーガーは BPPPB
(を 度回転したもの)、レベル バーガーは BBPPPBPBPPPBB
といった見た目になります。
高羽氏が作るのはレベル バーガーです。ダックスフンドのルンルンは、このバーガーの下から 層を食べます (パティまたはバン 枚を 層とします)。ルンルンはパティを何枚食べるでしょうか?
制約
- レベル バーガーの層の総数
- は整数である。
入力
入力は以下の形式で標準入力から与えられる。
出力
レベル バーガーの下から 層に含まれるパティの枚数を出力せよ。
入力例 1Copy
2 7
出力例 1Copy
4
レベル バーガー (BBPPPBPBPPPBB
) の下から 層にはパティが 枚含まれます。
入力例 2Copy
1 1
出力例 2Copy
0
レベル バーガーの一番下の層はバンです。
入力例 3Copy
50 4321098765432109
出力例 3Copy
2160549382716056
レベル バーガーは層の数が ビット整数に収まらない程度に分厚いです。
Score : points
Problem Statement
In some other world, today is Christmas.
Mr. Takaha decides to make a multi-dimensional burger in his party. A level- burger ( is an integer greater than or equal to ) is the following thing:
- A level- burger is a patty.
- A level- burger is a bun, a level- burger, a patty, another level- burger and another bun, stacked vertically in this order from the bottom.
For example, a level- burger and a level- burger look like BPPPB
and BBPPPBPBPPPBB
(rotated degrees), where B
and P
stands for a bun and a patty.
The burger Mr. Takaha will make is a level- burger. Lunlun the Dachshund will eat layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
Constraints
- the total number of layers in a level- burger
- and are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of patties in the bottom-most layers from the bottom of a level- burger.
Sample Input 1Copy
2 7
Sample Output 1Copy
4
There are patties in the bottom-most layers of a level- burger (BBPPPBPBPPPBB
).
Sample Input 2Copy
1 1
Sample Output 2Copy
0
The bottom-most layer of a level- burger is a bun.
Sample Input 3Copy
50 4321098765432109
Sample Output 3Copy
2160549382716056
A level- burger is rather thick, to the extent that the number of its layers does not fit into a -bit integer.