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

12587번 - Number Game (Small) 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB29242281.481%

문제

Arya and Bran are playing a game. Initially, two positive integers A and B are written on a blackboard. The players take turns, starting with Arya. On his or her turn, a player can replace A with A - k*B for any positive integer k, or replace B with B - k*A for any positive integer k. The first person to make one of the numbers drop to zero or below loses.

For example, if the numbers are initially (12, 51), the game might progress as follows:

  • Arya replaces 51 with 51 - 3*12 = 15, leaving (12, 15) on the blackboard.
  • Bran replaces 15 with 15 - 1*12 = 3, leaving (12, 3) on the blackboard.
  • Arya replaces 12 with 12 - 3*3 = 3, leaving (3, 3) on the blackboard.
  • Bran replaces one 3 with 3 - 1*3 = 0, and loses.

We will say (A, B) is a winning position if Arya can always win a game that starts with (A, B) on the blackboard, no matter what Bran does.

Given four integers A1, A2, B1, B2, count how many winning positions (A, B) there are with A1AA2 and B1BB2.

입력

The first line of the input gives the number of test cases, T. T test cases follow, one per line. Each line contains the four integers A1, A2, B1, B2, separated by spaces.

Limits

  • 1 ≤ T ≤ 100.
  • 1 ≤ A1A2 ≤ 1,000,000.
  • 1 ≤ B1B2 ≤ 1,000,000.
  • A2 - A1 ≤ 30.
  • B2 - B1 ≤ 30.

출력

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1), and y is the number of winning positions (A, B) with A1AA2 and B1BB2.

제한

예제 입력 1

3
5 5 8 8
11 11 2 2
1 6 1 6

예제 출력 1

Case #1: 0
Case #2: 1
Case #3: 20

힌트

출처

Contest > Google > Code Jam > Google Code Jam 2010 > Round 1A C1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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