PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000295. Đánh dấu ô (Marking)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đánh dấu ô (Marking)
Marking
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are squares numbered from to , initially unmarked. All squares are marked one by one using the following procedure.
- First, mark square .
- Let be the most recently marked square. Start with . While square is already marked, replace with . Mark the first unmarked square encountered and repeat.
The process ends after exactly marks. Find the index of the square marked in the -th operation, including the initial mark of square .
Input
One line containing three integers .
Output
Print the index of the square marked in the -th operation.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Examples 1
Input
4 2 3
Output
1
Explanation
The marking order is . On the third operation, square is marked already, so the next unmarked square is .
Examples 2
Input
5 8 5
Output
2
Explanation
With step size , the marking order is , so the fifth square is .