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

11249번 - Chasing 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB300584118.468%

문제

Tortoise and hare are chasing on circular race track of N section. Each section has a number start from 1, 2 … to N. (The section N is next to section 1.) This race track is oneway or in other word, if you are in section i, your next move will be going to section i+1 and if you are in section N, your next move will be going to section 1.

When the game starts, the hare is in section R and tortoise is in section T. In each turn, start with tortoise, tortoise will move for 1 section and hare will move for 2 sections. The game will end when tortoise and hare are in the same section. (The game can be ended even the hare has moved less than 2 section.) This game might take some time. You, as a referee, want to know how many turn will this game take. (1 turn includes moves of tortoise and hare. If tortoise and hare are in the same section at the start of the game, it takes 0 turns and the game ends immediately.)

Write a program that get a size of race track, starting position of tortoise and hare and find out how many turns will the game take.

입력

First line has a number K (1 ≤ K ≤ 100,000) represent number of test cases.

For next K lines, each line has three numbers Ni Ri Ti (1 ≤ Ni ≤ 1018, 1 ≤ Ri, Ti ≤ Ni) represent a size of race track, starting position of hare and tortoise in i-th test cases.

출력

Your output should have K lines. Each line represents the number of turns in i-th test cases.

제한

예제 입력 1

4
10 1 4
10 8 3
10 2 10
20 5 5

예제 출력 1

3
5
8
0

힌트

출처

ICPC > Regionals > Asia Pacific > Thailand > Thailand Central Group-B Programming Contest > Thailand Central Group-B Programming Contest 2015 C번

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

출처

대학교 대회

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

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