Codeforces Round #638 A.Phoenix and Balance(水题)

Phoenix has nn coins with weights 21,22,,2n21,22,…,2n. He knows that nn is even.

He wants to split the coins into two piles such that each pile has exactly n2n2 coins and the difference of weights between the two piles is minimized. Formally, let aa denote the sum of weights in the first pile, and bb denote the sum of weights in the second pile. Help Phoenix minimize |ab||a−b|, the absolute value of aba−b.

Input

The input consists of multiple test cases. The first line contains an integer tt (1t1001≤t≤100) — the number of test cases.

The first line of each test case contains an integer nn (2n302≤n≤30; nn is even) — the number of coins that Phoenix has.

Output

For each test case, output one integer — the minimum possible difference of weights between the two piles.

Example
Input
Copy
2
2
4
Output
Copy
2
6
因为两组的size都是n/2,所以最大的放进一组后,这组剩下的n/2-1个数一定都得是最小的(等比数列性质可知,an>sigma ai(i= 1 to n-1))。
复制代码
#include <bits/stdc++.h>
using namespace std;
long long fpow(long long a,long long b)
{
    long long ans=1;
    for(;b;b>>=1)
    {
        if(b&1)ans*=a;
        a*=a;
    }
    return ans;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long n,sum1=0,sum2=0;
        cin>>n;
        sum1+=fpow(2,n);
        sum1+=fpow(2,n/2)-2;
        sum2=fpow(2,n+1)-2-sum1;
        cout<<abs(sum1-sum2)<<endl;
    }
    return 0;
}
复制代码

 



posted @   脂环  阅读(297)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
主题色彩