fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int maxAND(long long int L, long long int R)
  5. {
  6. if (L == R)
  7. return L;
  8. else if ((R - L) == 1)
  9. return (R & L);
  10. else {
  11. if (((R - 1) & R) > ((R - 2) & (R - 1)))
  12. return ((R - 1) & R);
  13. else
  14. return ((R - 2) & (R - 1));
  15. }
  16. }
  17.  
  18.  
  19. int main() {
  20. int t;
  21. scanf("%d",&t);
  22. while(t--) {
  23. long long int p,q;
  24. scanf("%llu%llu",&p,&q);
  25. printf("%d\n",maxAND(p,q));
  26. }
  27. }
Success #stdin #stdout 0s 4356KB
stdin
2
2 3
4 8
stdout
2
6