#include #include #include using namespace std; // f(n): answer when elimination is from left (Mi's turn) long long f(long long n); // g(n): answer when elimination is from right (Razhki's turn) long long g(long long n) { if(n == 1) return 1; if(n % 2 == 0) { // even: survivors are those at positions 2,4,6,... return 2 * f(n / 2); } else { // odd: survivors are those at positions 1,3,5,... long long m = (n + 1) / 2; // = ceil(n/2) return 2 * f(m) - 1; } } long long f(long long n) { if(n == 1) return 1; long long m = (n + 1) / 2; // survivors count from left-to-right round return 2 * g(m) - 1; } int main(){ ifstream inFile("biscuits.in"); ofstream outFile("biscuits.out"); if(!inFile || !outFile) { cerr << "Error opening input or output file!" << endl; return 1; } int T; inFile >> T; vector answers; while(T--) { long long N; inFile >> N; // The game always starts with Mi (left-to-right elimination) answers.push_back(f(N)); } for(auto ans : answers) { outFile << ans << "\n"; } inFile.close(); outFile.close(); return 0; }