Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

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

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programmingoneonone | WordPress Theme by SuperbThemes