#abc290d. D - Marking
D - Marking
Score : points
问题描述
有 个正方形按顺序排列,编号从 到 。Snuke 将按照以下步骤标记每个正方形。
- 标记编号为 的正方形。
- 重复执行以下步骤 i - iii 共 次。
- 将变量 初始化为 ,其中 是上次标记的正方形的索引。
- 当正方形 已被标记时,重复将 替换为 。
- 标记正方形 。
找出 Snuke 第 次标记的正方形的索引。
给定 个测试用例,请分别找出它们的答案。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are squares indexed through arranged in a line. Snuke is going to mark every square by the following procedure.
- Mark square .
- Repeat the following steps i - iii times.
- Initialize a variable with , where is the index of the square marked last time.
- While square is marked, repeat replacing with .
- Mark square .
Find the index of the square that Snuke marks for the -th time.
Given test cases, find the answer for each of them.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format, where denotes the -th test case:
Each test case is given in the following format:
Output
Print lines.
The -th line should contain the answer to the -th test case.
Sample Input 1
9
4 2 1
4 2 2
4 2 3
4 2 4
5 8 1
5 8 2
5 8 3
5 8 4
5 8 5
Sample Output 1
0
2
1
3
0
3
1
4
2
If and , Snuke marks the squares as follows.
- Mark square .
- (-st iteration) Let . Since square is not marked, mark it.
(-nd iteration) Let . Since square is marked, let . Since square is not marked, mark it.
(-rd iteration) Let . Since square is not marked, mark it.
update @ 2024/3/10 12:07:04