【題解】Codeforces 1348A. Phoenix and Balance

【題目敘述】http://codeforces.com/contest/1348/problem/A

#include <iostream>
using namespace std;
 
int t, n;
long long a, b;
 
int main() {
    cin >> t;
    while (t--){
        cin >> n;
        a = 0;
        b = 0;
        for (int i = 1; i < n/2; i++){
            a += (1<<i);
        }
        for (int i = n/2; i < n; i++){
            b += (1<<i);
        }
        a += (1<<n);
        cout << a-b << "\n";
    }
}
分享本文 Share with friends