Interesting xor problem for march long challenge

problem code: IRSTXOR
i tried following code but it is giving me time limit exceeded error even with time complexity N.and this code is from their official editorial

‘’’
#include
#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int d;
long long a,b,c;

   int id=0;
    int f=1;
    for(int i=31;i>=0;i--)
    {
       if((1<<i)&c)
       {
           id=i;
           break;
       }
    }
    for(int i=id;i>=0;i++)
    {
        if((1<<i)&c)
    {
        if(f)
        {
          a|=1<<i;
          f=0;
        }
        else
        {
            b|=1<<i;
        }
        
    }
    else
    {
        a|=1<<i;
        b|=1<<i;
    }
    }
    cout<<a*b<<endl;
}

return 0;

}
‘’

To format code, use three backticks, not three single quotes :slight_smile:

1 Like

wasn’t this suppose to be i-- ?

sorry i was away for a while
thanks for answering.i can’t understand how i didn’t notice that :sweat_smile: :sweat_smile: :sweat_smile: