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

33396번 - Billiard 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB71412552.083%

문제

There is a table with length $n$ and width $m$.

A billiard ball begins to move from one corner with an angle of 45ドル$ degrees.

When will the ball bounce back to where it starts?

Formally, you are given $n$ and $m,ドル and you need to calculate the return value of the following function.

int64_t check(int n, int m) {
 int x = 0, y = 0;
 int dx = 1, dy = 1;
 int64_t t = 0;
 while (1) {
 if (x + dx < 0) dx *= -1;
 if (x + dx > n) dx *= -1;
 if (y + dy < 0) dy *= -1;
 if (y + dy > m) dy *= -1;
 x += dx;
 y += dy;
 ++t;
 if (x == 0 && y == 0) break;
 }
 return t;
}

입력

The first line contains an integer $t,ドル the number of test cases (1ドル \le t \le 10^5$). The test cases follow.

Each test case is described by a single line containing two integers $n$ and $m$ (2ドル \le n, m \le 10^9$).

출력

For each test case, output a line containing one integer: the answer to the problem.

제한

예제 입력 1

5
2 2
2 3
2 4
2 5
2 6

예제 출력 1

4
12
8
20
12

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2023 > Day 7: Peking U Contest E번

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

출처

대학교 대회

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

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