题解:P17088 轻舟已过

· · 题解

题意:给偶数n,找小于2^n的最大x,设k是x二进制1的个数,要求lowbit(x)=2^k。

构造方式:高位k-1个1,后面空

式子:$ans = (2^{k-1}-1) \times 2^k,k=n/2

C++代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    cout<<((1ll<<(n/2))-1)*(1ll<<(n/2));
    return 114514*137891*1919810*917813*114514*137891*1919810*917813*114514*137891*1919810*917813*114514*137891*1919810*917813;
    cout<<"我要投诉你。";
    cout<<"I want to tousu you.";
    cout<<"请输入文本。";
    cout<<"Please enter text.";
    cout<<"何意味?";
    cout<<"what's the meaning?";//防伪标识
}