#abc319e. E - Bus Stops
E - Bus Stops
Score : points
问题描述
高桥最初位于自己的房子,并打算前往青木的家。
在两家房子之间有 个公交车站,编号为 到 ,高桥可以通过以下方式在这些车站间移动:
- 他可以在 单位时间内步行从自己家走到第 号公交车站。
- 对于每个 ,从第 号公交车站出发的公交车在每个时间为 的倍数时发车,通过乘坐这辆公交车,他可以在 单位时间内到达第 号公交车站。这里,条件保证了 。
- 高桥可以在 单位时间内从第 号公交车站步行到青木的家。
对于每个 ,处理以下查询请求。
当高桥在时间 离开自己家时,找出他最早能到达青木家的时间。
注意,如果他恰好在一辆公交车的发车时间到达某个公交车站,那么他可以乘坐那辆公交车。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi is initially at his house and is about to visit Aoki's house.
There are bus stops numbered to between the two houses, and Takahashi can move between them in the following ways:
- He can walk from his house to bus stop in units of time.
- For each , a bus departs from bus stop at each time that is a multiple of , and by taking this bus, he can get to bus stop in units of time. Here, the constraints guarantee that .
- Takahashi can walk from bus stop to Aoki's house in units of time.
For each , process the following query.
Find the earliest time that Takahashi can arrive at Aoki's house when he leaves his house at time .
Note that if he arrives at a bus stop exactly at the departure time of a bus, he can take that bus.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. For each , the -th line should contain the answer to the -th query.
Sample Input 1
4 2 3
5 4
6 6
3 1
7
13
0
710511029
136397527
763027379
644706927
447672230
Sample Output 1
34
22
710511052
136397548
763027402
644706946
447672250
For the first query, Takahashi can move as follows to arrive at Aoki's house at time .
- Leave his house at time .
- Walk from his house and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Walk from bus stop and arrive at Aoki's house at time .
For the second query, Takahashi can move as follows and arrive at Aoki's house at time .
- Leave his house at time .
- Walk from his house and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Walk from bus stop and arrive at Aoki's house at time .
update @ 2024/3/10 09:07:40