solution

grandy数。

implementation

#include <iostream>
#include <vector>
#include <set>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
template <typename C>
int mex(C const & xs) {
    int y = 0;
    for (int x : xs) { // xs must be sorted (duplication is permitted)
        if (y <  x) break;
        if (y == x) ++ y;
    }
    return y;
}
int main() {
    int n; cin >> n;
    vector<int> grandy(n+1);
    repeat (x,n+1) {
        set<int> s;
        if (x >= 2) {
            if (x % 2 == 0) {
                s.insert(grandy[x/2] ^ grandy[x/2]);
            } else {
                s.insert(grandy[x/2] ^ grandy[x/2+1]);
            }
        }
        if (x >= 3) {
            if (x % 3 == 0) {
                s.insert(grandy[x/3] ^ grandy[x/3] ^ grandy[x/3]);
            } else if (x % 3 == 1) {
                s.insert(grandy[x/3] ^ grandy[x/3] ^ grandy[x/3+1]);
            } else {
                s.insert(grandy[x/3] ^ grandy[x/3+1] ^ grandy[x/3+1]);
            }
        }
        grandy[x] = mex(s);
    }
    cout << (grandy[n] ? "A" : "B") << endl;
    return 0;
}