Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Maximum AND problem solution

YASH PAL, 31 July 2024
In this HackerEarth Maximum AND problem solution we have given two numbers A and B. Find the value of pair (P, Q) such that A <= P < Q <= B value of P AND Q is maximum where AND is a binary operator.
HackerEarth Maximum AND problem solution

HackerEarth Maximum AND problem solution.

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
int main()
{
ios_base::sync_with_stdio(false);
int t;
cin>>t;
assert(t>=1 && t<=1000);
while(t--)
{
ll a,b,ans;
cin>>a>>b;
assert(b>=1 && b<=1000000000000000000LL && a>=1 && a<b);
if(b-a+1<3)
ans=(a&b);
else if(b&1)
ans=(b&(b-1));
else
ans=((b-1)&(b-2));
cout<<ans<<endl;
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes