Transmission Door
There are 2 piles of stones. A B Two people take turns, a take first. Each time you can take any or 2 of the same number of stones from a heap, but not to be taken. The man who got the last 1 stones won. Suppose a B is very clever, there is no mistake in the process of taking the stone. Give the number of 2 stones and ask who will win the game at the end.
For example, 2 stones were 3 and 5. So no matter a how to take, B has a corresponding method to get the last 1.
Input
Line 1th: A number t that represents the number of numbers that are later used as input tests. (1 <= T <= 10000)
Section 2-t + 1 lines: 2 numbers per row are 2 piles of stones, separated by spaces. (1 <= N <= 10^18)
Output
A total of T-lines, if a WINS output A, if B wins output B.
Input example
3
3 5
3 4
1 9
Output example
B
A
A
Problem Solving Ideas:
If the range of data in this topic is not very large, multiply it directly. (sq RT(5)+1) 2 On the line, but in this topic, the data range is too large, if the direct multiplication will have a precision problem, so we reduce the accuracy problem, will 0.618033988749894848204586834 ... Split the integer into the array, split it into three parts, and then multiply to reduce the loss of precision. See the code specifically:
< Span class= "Mrow" id= "mathjax-span-1146" >m y Span style= "Display:inline-block; width:0px; Height:2.616em; " > Code
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>using namespace STD;typedef Long LongLL; LL tmp[3] = {618033988,749894848,204586834}; LL MOD =1000000000;intMain () {intT LL m, N;Cin>>T; while(t--) {Cin>>m>>n;if(M < n) swap (n, m); LL cha = m-n; LL ta = cha/mod, TB = cha%mod; LL TP = tb*tmp[2]; TP = ta*tmp[2] + tb*tmp[1] + tp/mod; TP = ta*tmp[1] + tb*tmp[0] + tp/mod; TP = Cha + ta*tmp[0] + tp/mod;if(tp = = N)puts("B");Else puts("A"); }return 0;}
51NOD 1185 Witzov Game V2 (game theory + reduced accuracy)