社区讨论

神秘 TLE 求调

P13686 【MX-X16-T4】「DLESS-3」XOR and Split参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@mhjhwjdq
此快照首次捕获于
2025/11/04 02:50
4 个月前
此快照最后确认于
2025/11/04 02:50
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
inline int read(){
	int x=0,f=1;
	char ch=getchar_unlocked();
	while (!isdigit(ch)){
		if (ch=='-') 
			f=-1;
		ch=getchar_unlocked();
	}
	while (isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar_unlocked();
	}
	return x*f;
}
inline void write(int x){
	if (x<0)putchar('-'),x=-x;
	if (x>9)write(x/10);
	putchar(x%10+'0');
}
ll log2(ll n){
    int b=1,cnt=0;
    while (b<=n)b<<=1,cnt++;
    return cnt-1;
}
ll f(ll n){
    ll k=log2(n);
    return 1LL<<k;
}
int main(){
    int T;T=read();
    while(T--){
        ll n;n=read();
        if(n==1)puts("1");
        else if (n==2)puts("3");
        else if(n==3)puts("2");
        else{
            ll m=f(n);
            if(m==n)write(n),putchar('\n');
            else write(m*2-1),putchar('\n');
        }
    }
    return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...