#P12235. Dodge the Cannonball

    ID: 14341 Type: Default 1000ms 256MiB

Dodge the Cannonball

Dodge the Cannonball

Blue is playing a game of dodging cannonballs. In the game, there is a character controlled by Blue and a turret. Initially, the distance between them is an integer \(n\). The turret will choose an integer \(x\) from the interval \([L, R]\) and fire a cannonball. The cannonball will only land at distances that are multiples of \(x\) (i.e. at \(x, 2x, 3x, \ldots\)) and then bounce back into the air. If the character happens to be exactly at one of these landing positions, the game ends immediately.

Blue can move the character before the cannonball is fired. Each move changes the distance between the turret and the character by exactly \(1\) (either increasing or decreasing the distance by \(1\)). Blue wants to know the minimum number of moves required to guarantee that the character will not be hit, regardless of which \(x\) in \([L, R]\) the turret chooses.

Important note: The cannonball lands only at positive multiples of \(x\). In other words, if the final distance is \(0\) or a positive integer smaller than \(L\), then no \(x\) from \([L, R]\) can divide the distance, hence the character is safe.

Task: Given integers \(n\), \(L\), and \(R\), determine the minimum number of moves required so that the final distance from the turret is not divisible by any integer \(x\) in \([L, R]\) (except that if the final distance is 0, it is automatically safe).

inputFormat

The first and only line of input contains three space-separated integers \(n\), \(L\), and \(R\) where:

  • \(n\) is the initial distance between the turret and the character.
  • \(L\) and \(R\) define the interval from which the turret may choose its shot multiplier \(x\).

It is guaranteed that \(0 \le n \le 10^5\) and \(1 \le L \le R \le 10^5\). (Note: These constraints are for illustration and may be adjusted.)

outputFormat

Output a single integer: the minimum number of moves required so that no matter what integer \(x\) (with \(L \le x \le R\)) is chosen by the turret, the final distance (after moving) is not a multiple of \(x\). Remember that if the final distance is \(0\), it is considered safe.

sample

10 4 6
1