Logo
(追記) (追記ここまで)

16867번 - Difference 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB130342632.911%

문제

A smallest different sequence (SDS) is a sequence of positive integers created as follows: A1 = r ≥ 1. For n > 1, An = An−1 + d, where d is the smallest positive integer not yet appearing as a value in the sequence or as a difference between two values already in the sequence. For example, if A1 = 1, then since 2 is the smallest number not in our sequence so far, A2 = A1 + 2 = 3. Likewise A3 = 7, since 1, 2 and 3 are already accounted for, either as values in the sequence, or as a difference between two values. Continuing, we have 1, 2, 3, 4, 6, and 7 accounted for, leaving 5 as our next smallest difference; thus A4 = 12. The next few values in this SDS are 20, 30, 44, 59, 75, 96, . . . For a positive integer m, you are to determine where in the SDS m first appears, either as a value in the SDS or as a difference between two values in the SDS. In the above SDS, 12, 5, 9 and 11 first appear in step 4.

입력

Input consists of a single line containing two positive integers A1 m (1 ≤ r ≤ 100, 1 ≤ m ≤ 200 000 000).

출력

Display the smallest value n such that the sequence A1, . . . , An either contains m as a value in the sequence or as a difference between two values in the sequence. All answers will be ≤ 10 000.

제한

예제 입력 1

1 5

예제 출력 1

4

예제 입력 2

1 12

예제 출력 2

4

예제 입력 3

5 1

예제 출력 3

2

힌트

출처

ICPC > Regionals > North America > East Central North America Regional > 2018 East Central Regional Contest B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /