(大数博弈)1068 Bash游戏 V3

1068 Bash游戏 V3

  1. 1 秒
  2.  
  3. 131,072 KB
  4.  
  5. 20 分
  6.  
  7. 3 级题

有一堆石子共有N个。A B两个人轮流拿,A先拿。每次拿的数量只能是2的正整数次幂,比如(1,2,4,8,16....),拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。

例如N = 3。A只能拿1颗或2颗,所以B可以拿到最后1颗石子。(输入的N可能为大数)

 收起

输入

第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000)
第2 - T + 1行:每行1个数N。(1 <= N <= 10^1000)

输出

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

输入样例

3
2
3
4

输出样例

A
B
A
import java.util.*;
import java.math.*;
public class Main{
    public static void main(String[] args){
    	Scanner in=new Scanner(System.in);
    	int t=in.nextInt();
    	BigInteger a=new BigInteger("3");
    	while(t>0){
    		BigInteger n=in.nextBigInteger();
    	//	System.out.println(n);
    	//	System.out.println(n.mod(a));
    		if(n.mod(a).equals(BigInteger.ZERO))
    			System.out.println("B");
    		else System.out.println("A");
    		t--;
    	}
    }
}

猜你喜欢

转载自blog.csdn.net/black_horse2018/article/details/89035879