ICPC Square

시간 제한1초메모리 제한2048 MB

요약
N, D, 시작 층 S가 주어질 때 x에서 x의 배수 y 중 y-x<=D인 층으로 이동하며 도달할 수 있는 가장 높은 층을 구한다.
난이도

보통10점 중 7점

유형
정수론, 그리디, 수학, 이분 탐색
정답자
아직 제출이 없습니다

문제

ICPC Square is a hotel provided by the ICPC Committee for the accommodation of the participants. It consists of NN floors (numbered from 11 to NN). This hotel has a very unique elevator. If a person is currently at floor xx, by riding the elevator once, they can go to floor yy if and only if yy is a multiple of xx and y−x≤Dy - x ≤ D.

You are currently at floor SS. 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 NN DD SS (2≤N≤10122 ≤ N ≤ 10^{12}; 1≤D≤N−11 ≤ D ≤ N - 1; 1≤S≤N1 ≤ S ≤ N).

출력

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

예제2

  1. 예제 1

    입력
    64 35 3
    
    예상 출력
    60
    
  2. 예제 2

    입력
    2024 2023 1273
    
    예상 출력
    1273