#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 { // If none of the conditions are met, there's no valid sequence return ""; } } // Reverse the recorded operations to get the correct sequence std::string result; for (auto it = operations.rbegin(); it != operations.rend(); ++it) { result += *it; } return result; } int main() { int N; std::cin >> N; std::string result = find_operations(N); std::cout << result << std::endl; return 0; }