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

13069번 - Beehive 다국어

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

문제

There is an infinite beehive like the one given in the figure. We consider two cells to be adjacent if and only if they share a side. A path of length k from cell c0 to cell ck is a sequence of cells c0, c1, . . . , ck such that ci and ci+1 are adjacent for all 0 ≤ i < k. The distance between cells i and j is the length of the shortest path from cell i to cell j.

The cells of the beehive are indexed using positive integers as shown. The cells with larger distance from cell 1 are given larger indices. The indices of cells with the same distance from cell 1 increases from left to right. Each positive integer is the index of exactly one cell.

We want to know the distance of two cells whose indices are given.

입력

There are multiple test cases in the input. Each test case is a single line containing two space-separated integers i and j as the indices of two cells (1 ≤ i, j ≤ 104). The input terminates with a line containing 0 0 which should not be processed as a test case.

출력

For each test case, output a single line containing the distacne of the given cells.

제한

예제 입력 1

8 4
11 12
365 365
0 0

예제 출력 1

2
5
0

힌트

출처

ICPC > Regionals > Asia West Continent > Iran > Tehran Site 2015 G번

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

출처

대학교 대회

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

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