跳到正文

题解

题解:P17088 轻舟已过

TangLingxin约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年7月11日
收录
2026年10月5日
更新
2026年11月10日
篇幅
约 1 分钟
获赞
1
题目
P17088

版本

  1. v1当前

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

构造方式:高位k−1k-1个11,后面空 kk位(第kk位是11,底下k−1k-1个00)

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

C++代码:

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?";//防伪标识
}
原文