title: Maximum value of AND operation
body: <p>Given two numbers A and B. Find the value of pair (P,Q) such that A &lt;= P &lt; Q &lt;= B value of P AND Q is maximum where AND is a binary operator. Refer to this link for more information about AND operator</p>
  
  <pre><code>1&lt;= A &lt; B &lt;=10^18
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>int main()
  {
      int t;
      cin&gt;&gt;t;
      while(t--){
          long long int nearpow =0;
          int count=1;
          int a ; int b;
          cin&gt;&gt;a&gt;&gt;b;
  
          while(nearpow&lt;=b){
  
              nearpow = 1&lt;&lt;count;
              count++;
  
          }
          nearpow/=2;
  
          if(nearpow==b){
              long long int x = b-1;
              long long int y = b-2;
              if(y&gt;=a) cout&lt;&lt;(x&amp;y)&lt;&lt;endl;
              else cout&lt;&lt;(b&amp;x)&lt;&lt;endl;
          }else{
              long long int max=0;
              cout&lt;&lt;(b&amp;(b-1))&lt;&lt;endl;
  
          }
  
      }
      return 0;
  }
  </code></pre>
  
  <p>I am getting the wrong answer from this approach . where i am wrong ? Please Help</p>