#MTH000000018. Khách sạn vô hạn phòng (The Hotel with Infinite Rooms)
Khách sạn vô hạn phòng (The Hotel with Infinite Rooms)
The Hotel with Infinite Rooms
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A hotel has infinitely many rooms, and only one group occupies the hotel at a time.
The first group has members and arrives on day . A group of members stays for exactly days. On the next morning after that group leaves, a new group of members arrives and stays for days. This continues forever.
Given day , counted from the first day, determine the size of the group staying in the hotel on day .
Input
One line contains two integers and .
Output
Print the size of the group staying in the hotel on day .
Subtasks
- Subtask 1 (20%): .
- Subtask 2 (30%): .
- Subtask 3 (50%): Full constraints: , .
Examples
Input
3 10
Output
5
Explanation
The group of stays on days through , the group of on days through , and the group of on days through . Day is in the last interval, so the answer is .