HDU 5969 最大的位或

Problem Description

B君和G君聊天的时候想到了如下的问题。
给定自然数l和r ,选取2个整数x,y满足l <= x <= y <= r ,使得x|y最大。
其中|表示按位或,即C、 C++、 Java中的|运算。

 

 

Input

包含至多10001组测试数据。
第一行有一个正整数,表示数据的组数。
接下来每一行表示一组数据,包含两个整数l,r。
保证 0 <= l <= r <= 1018。

 

 

Output

对于每组数据输出一行,表示最大的位或。

 

 

Sample Input

 

5 1 10 0 1 1023 1024 233 322 1000000000000000000 1000000000000000000

 

 

Sample Output

 

15 1 2047 511 1000000000000000000

 

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include<cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string.h>
#include<bitset>
typedef long long ll;

using namespace std;
const int   inf=0x3f3f3f3f;
//int inf  = 2e7+100;

vector<int > v[11111],l[11111];
vector<int> ans;
map<string ,int > mp,vism;
map<int ,string>mp2;
map<string,map<string ,int > >in;

int n,m,s,num;
int   G[2222][2222];
int   vis[1111],d[22222],p[22222],o[11111],f[11111];
char c[22222];

int dd[11111111];



int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        long long int a,b,c;
        scanf("%lld%lld",&a,&b);
        if(a==b)
        {
            printf("%lld\n",a);
            continue;
        }
        long long int sum=0;
        long long int t=0;
        //cout<<b<<endl;
        for(int i=0;a+t<b;i++)
        {

            t+=((long long)1<<i);
            long long int t1;
            //cout<<1<<endl;
             t1=((a|t)|b);
              // cout<<2<<endl;
            b=max(b,t1);
        }
        //cout<<2<<endl;
        printf("%lld\n",b);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值