#5535. [GCJ 2010 #1A] Number Game
[GCJ 2010 #1A] Number Game
[GCJ 2010 #1A] Number Game
题目描述
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 \times B$ for any positive integer $k$, or replace $B$ with $B - k \times 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 , the game might progress as follows:
- Arya replaces with , leaving on the blackboard.
- Bran replaces with , leaving on the blackboard.
- Arya replaces with , leaving on the blackboard.
- Bran replaces one with , and loses.
We will say is a winning position if Arya can always win a game that starts with on the blackboard, no matter what Bran does.
Given four integers , , , , count how many winning positions there are with and .
输入格式
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 $A_1$, $A_2$, $B_1$, $B_2$, separated by spaces.输出格式
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 $A_1 \leq A \leq A_2$ and $B_1 \leq B \leq B_2$.3
5 5 8 8
11 11 2 2
1 6 1 6
Case #1: 0
Case #2: 1
Case #3: 20
提示
**Limits**Small dataset (16 Pts, Test set 1 - Visible)
- Time limit:
303 seconds.
Large dataset (25 Pts, Test set 2 - Hidden)
- Time limit:
909 seconds. - No additional constraints. 标签: P13392|博弈论|2010|Google Code Jam