Sum vs XOR

  • + 0 comments
    int count = 0;
     for(long i =0; i<=n; i++){
         long x = n + i;
         long y = n ^ i;
         if(x == y){
           count++;
         }
     }
    return count;