P25383 [AtCoder] Takahashi's Return
省选
题目描述

Problem Description

You are playing an RPG game. In this game, you, as the hero Takahashi, travel from the human world to the magical world to fight the demon king. You have trained Takahashi's magical power and finally defeated the demon king. Peace has come to both the human and magical worlds, but the story is not over yet. Takahashi needs to return from the magical world to the human world.

The passage connecting the magical and human worlds consists of $ N $ doors numbered $1,\ 2,\ ...,\ N$ and one magic circle. To move from the magical world to the human world, you need to pass through these $ N $ doors in order once each, and then enter the magic circle.

In the magical world, there is a special hat called the magic hat. When passing through the passage, you must pass through exactly one door wearing the magic hat and all other doors without the magic hat.

People in the magical world have magical energy, which changes as they pass through the doors. When entering the magic circle, for safety reasons, the size of the magical energy must be between $ L $ and $ R $ inclusive.

The changes in the size of magical energy when passing through the doors are as follows. When a person with magical energy of size $ x $ passes through door $ i $, the size of the magical energy $ y $ after passing depends on the values of $x,\ i$ and whether the person was wearing the magic hat:

  • If not wearing the magic hat,
  • if $ x < i $, then $ y = x + i $
  • if $x \geq i$, then $ y = x - i $
  • If wearing the magic hat, regardless of the relationship between $ x $ and $ i $, $ y = x + i $

Takahashi, with magical energy of size $ 0 $ and carrying the magic hat, enters the passage connecting the magical and human worlds. There are $ N $ ways to choose which door to pass through wearing the magic hat. How many of these ways allow Takahashi to safely enter the magic circle?

Input Format

The input is given from the standard input in the following format:

$ N $ $ L $ $ R $

Output Format

Output the answer in one line.

Sample Input and Output

Sample Input #1

3 5 7

Sample Output #1

1

Sample Input #2

5 67 89

Sample Output #2

0

Sample Input #3

1357 500 5000

Sample Output #3

1354

Notes/Hints

Constraints

  • $1 \leq N \leq 10^{18}$
  • $0 \leq L \leq R \leq 10^{18}$

Sample Explanation 1

If the magic hat is worn when passing through door $ 1 $ or door $ 2 $, the size of the magical energy changes as $0 \rightarrow 1 \rightarrow 3 \rightarrow 0$. These choices do not satisfy the condition. If the magic hat is worn when passing through door $ 3 $, the size of the magical energy changes as $0 \rightarrow 1 \rightarrow 3 \rightarrow 6$. This choice satisfies the condition. Therefore, there is $ 1 $ way to wear the hat that satisfies the condition.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 5 7
样例输出
1