1072 威佐夫游戏

基准时间限制:秒 空间限制:131072 KB

2堆石子。A B两个人轮流拿,A先拿。每次可以从一堆中取任意个或从2堆中取相同数量的石子,但不可不取。拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出2堆石子的数量,问最后谁能赢得比赛。

例如:2堆石子分别为3颗和5颗。那么不论A怎样拿,B都有对应的方法拿到最后1颗。

Input

1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)

2 - T + 1行:每行2个数分别是2堆石子的数量,中间用空格分隔。(1 <= N <= 2000000)

Output

T行,如果A获胜输出A,如果B获胜输出B

Input示例

3

3 5

3 4

1 9

Output示例

B

A

A

 

--------------------

首先求出差值,差值 * 1.618 == 最小值 的话后手赢,否则先手赢。 第一个值 差值 * 1.618 

-------------------

import java.util.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        int n,m,temp;
        while(t-->0){
            n=sc.nextInt();
            m=sc.nextInt();
            
            if(n>m)
            {
                temp=n;
                n=m;
                m=temp;
            }
            temp=(int)((m-n)*(Math.sqrt(5)+1)/2);
            if(n==temp) System.out.println("B");
            else
                System.out.println("A");
        }
        
        
        sc.close();
        

    }

}