QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#9658. 소수 게임

Statistics

Alice와 Bob은 늘 서로 게임을 하는 것을 좋아하며, 오늘은 소수에 관한 새로운 게임을 찾았다.

게임에는 두 양의 정수 $x$와 $y$가 있고, Alice와 Bob이 번갈아 차례를 가진다. 매 차례 현재 플레이어는 정수 하나를 선택해 $1$을 뺄 수 있다 ($(x, y)$를 $(x - 1, y)$ 또는 $(x, y - 1)$로 바꾼다). 다음 조건 중 하나가 충족되면 게임이 종료되고 동시에 승자가 정해진다.

  • $x$ 또는 $y$가 $K$와 같으면 Bob이 이긴다.
  • $x$와 $y$가 모두 소수이면 Alice가 이긴다.
  • 위 두 조건이 동시에 충족되면 Bob이 이긴다.

이제 $x, y, K$와 누가 먼저 움직이는지가 주어진다. 두 사람이 모두 최적으로 플레이할 때 최종 승자가 누구인지 판단할 수 있는가?

입력

입력의 첫째 줄에는 테스트 케이스 수를 나타내는 정수 $T$가 주어진다. 그다음 $T$개 줄에는 각각 테스트 케이스 하나가 주어진다.

각 테스트 케이스에는 정확히 공백 하나로 구분된 네 정수 $x, y, K$와 $w$가 주어진다. $x,y,K$는 위에서 설명한 값이다. Alice가 먼저 움직이면 $w = 0$이고, Bob이 먼저 움직이면 $w = 1$이다.

출력

각 테스트 케이스에 대해 한 줄에 Case x: name을 출력한다. 여기서 x는 1부터 시작하는 테스트 케이스 번호이고, name은 게임에서 이길 플레이어의 이름이다.

예제

입력 1

4
4 9 2 0
7 10 2 0
6 39 2 0
5 28 2 0

출력 1

Case 1: Alice
Case 2: Alice
Case 3: Alice
Case 4: Bob

참고

$1 \le T \le 100$

$2 \le x, y \le 10^6$

$2 \le K \le \min(x, y)$

$0 \le w \le 1$

테스트 케이스의 $90\%$에 대해: $\max(x, y) \le 1000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.