#P15669. [ICPC 2024 Jakarta R] ICPC Square

[ICPC 2024 Jakarta R] ICPC Square

题目描述

ICPC Square is a hotel provided by the ICPC Committee for the accommodation of the participants. It consists of N N floors (numbered from 1 1 to N N ). This hotel has a very unique elevator. If a person is currently at floor x x , by riding the elevator once, they can go to floor y y if and only if y y is a multiple of x x and yxD y - x \leq D .

You are currently at floor S S . You want to go to the highest possible floor by riding the elevator zero or more times. Determine the highest floor you can reach.

输入格式

A single line consisting of three integers N N D D S S ( $ 2 \leq N \leq 10^{12}; 1 \leq D \leq N - 1; 1 \leq S \leq N $ ).

输出格式

Output a single integer representing the highest floor you can reach by riding the elevator zero or more times.

64 35 3
60
2024 2023 1273
1273

提示

Explanation for the sample input/output #1

First, ride the elevator from floor 3 3 to floor 15 15 . This is possible because 15 15 is a multiple of 3 3 and 15335 15 - 3 \leq 35 . Then, ride the elevator from floor 15 15 to floor 30 30 . This is possible because 30 30 is a multiple of 15 15 and 301535 30 - 15 \leq 35 . Finally, ride the elevator from floor 30 30 to floor 60 60 . This is possible because 60 60 is a multiple of 30 30 and 603035 60 - 30 \leq 35 .