Takahashi and Aoki are playing a stone-taking game. Initially, there are N piles of stones, and the i-th pile contains Ai stones and has an associated integer Ki.
Starting from Takahashi, Takahashi and Aoki take alternate turns to perform the following operation:
- Choose a pile. If the i-th pile is selected and there are X stones left in the pile, remove some number of stones between 1 and floor(X⁄Ki) (inclusive) from the pile.
The player who first becomes unable to perform the operation loses the game. Assuming that both players play optimally, determine the winner of the game. Here, floor(x) represents the largest integer not greater than x.
Constraints- 1≤N≤200
- 1≤Ai,Ki≤109
- All input values are integers.
Input is given from Standard Input in the following format:
NA1 K1:AN KNOutput
If Takahashi will win, print Takahashi
; if Aoki will win, print Aoki
.
25 23 3Sample Output 1
Aoki
Initially, from the first pile at most floor(5⁄2)=2 stones can be removed at a time, and from the second pile at most floor(3⁄3)=1 stone can be removed at a time.
- If Takahashi first takes two stones from the first pile, from the first pile at most floor(3⁄2)=1 stone can now be removed at a time, and from the second pile at most floor(3⁄3)=1 stone can be removed at a time.
- Then, if Aoki takes one stone from the second pile, from the first pile at most floor(3⁄2)=1 stone can be removed at a time, and from the second pile no more stones can be removed (since floor(2⁄3)=0).
- Then, if Takahashi takes one stone from the first pile, from the first pile at most floor(2⁄2)=1 stone can now be removed at a time, and from the second pile no more stones can be removed.
- Then, if Aoki takes one stone from the first pile, from the first pile at most floor(1⁄2)=0 stones can now be removed at a time, and from the second pile no more stones can be removed.
No more operation can be performed, thus Aoki wins. If Takahashi plays differently, Aoki can also win by play accordingly.
Sample Input 233 24 35 1Sample Output 2
TakahashiSample Input 3
328 316 419 2Sample Output 3
AokiSample Input 4
43141 5926535 89793 238462 64Sample Output 4
Takahashi 这种题只能打表找规律啊QWQ 把k<=10,n<=30的sg函数打表出来,找了找规律,发现: sg(x) = ( x%k==0 ? x/k : sg(x - x/k - 1) ) 当k比较小的时候,显然 x - x/k -1 的减小速率是非常快的,大致和k同阶(可能略大一点); 当k比较大的时候,可以发现在减小的过程中很多x/k都是一样的,并且一样的都是连续的,所以我们对于 x/k == i 可以计算出 x'/k 第一次
#include#define ll long longusing namespace std;const int N=205;int n,A,k,Xor;inline int Get(int x){ if(x =lef) return Get(x-der); else return Get(x-lef/der*der);}int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",&A,&k); Xor^=Get(A); } if(Xor) puts("Takahashi"); else puts("Aoki"); return 0;}