ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214919 | #3855. 好数 | drdilyor | 0 | 517ms | 1164kb | C++11 | 1.2kb | 2024-11-24 09:03:32 | 2024-11-24 13:14:14 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
signed main(){
int q=read();
while(q--){
int l=read(),r=read();
if(l<=3&&3<=r){
cout<<3<<"\n";continue;
}
bool f=0;
for(int i=2;i<=30;i++){
//ctz(x)=i.
//ppc(x)=i.
//l<=x*(1<<(i+1))+(1<<i)<=r
if((1<<i)>r){continue;}
int lb=(l+(1<<i)-1)/(1<<(i+1)),rb=(r-(1<<i))/(1<<(i+1));
if((1<<(i-1))-1>rb){
continue;
}
if(lb>((1<<(i-1))-1)){
for(int j=i-2;j<=30;j++){
//i-2 个.
if((1<<j)+(1<<(i-2))-1<=rb){
int v=(1<<j);
int cc=i-2;
for(int k=j-1;k>=0;k--){
if(!cc)break;
if(v+(1<<k)+(1<<(cc-1))-1<=rb){
cc--,v+=(1<<k);
}
}
if(v>=lb){
cout<<v*(1<<(i+1))+(1<<i)<<"\n";
f=1;break;
}
}
}
if(f)break;
}
else{
cout<<(1<<i)+(1<<(i+1))*((1<<(i-1))-1)<<"\n";
f=1;break;
}
//lb~rb 找 ppc=i-1 的.
}
if(!f)cout<<-1<<"\n";
}
return 0;
}
//look at my code
//my code is amazing
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 30
Accepted
time: 0ms
memory: 1164kb
input:
1 999995700 1000000000
output:
-1
result:
ok Accepted! >_<
Test #2:
score: 0
Accepted
time: 177ms
memory: 1160kb
input:
100000 7857167 7862247 8344618 8348655 8382478 8388566 8315927 8321011 8246290 8250342 8382480 83885...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 8370176 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...
result:
ok Accepted! >_<
Test #3:
score: 0
Accepted
time: 49ms
memory: 1160kb
input:
100000 3166357 3545086 7423160 8325545 9361438 9604609 5203715 5701815 8677014 9311476 6233360 68575...
output:
3407888 7864352 9437192 5242888 8912904 6291464 7077920 3145736 7962752 1638416 4718600 8912904 5799...
result:
ok Accepted! >_<
Test #4:
score: -30
Wrong Answer
time: 185ms
memory: 1160kb
input:
100000 8250369 8255487 8119297 8124415 7857153 7862271 6284289 6289407 8373249 8378367 8365057 83701...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer 3 is not a valid number.
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 106ms
memory: 1160kb
input:
100000 8382464 8388612 7332864 7337984 8250368 8255488 8119296 8124416 8373248 8378368 8348672 83537...
output:
8388612 7332864 8250368 8119296 8373248 8348672 8315904 4187136 8250368 8315904 8348672 6284288 4178...
result:
wrong answer 3 is not a valid number.
Subtask #3:
score: 0
Skipped