#include #include #include std::string find_operations(int N) { std::vector operations; while (N > 1) { if ((N - 1) % 3 == 0 && (N - 1) / 3 >= 1) { operations.push_back('B'); N = (N - 1) / 3; } else if ((N - 1) % 2 == 0 && (N - 1) / 2 >= 1) { operations.push_back('A'); N = (N - 1) / 2; } else { // This branch should not be reached due to the problem constraints // N must be reachable from 1 using the operations return ""; } } // Reverse the recorded operations to get the correct sequence std::string result(operations.rbegin(), operations.rend()); return result; } int main() { int N; std::cin >> N; std::string result = find_operations(N); std::cout << result << std::endl; return 0; }