Could anyone help me please in finding what’s wrong in my code. I’m getting wrong answer.I tried to find error but couldn’t find.

Below is my code.

#include <stdio.h>

int main(void) {
int t;
scanf(“%d”,&t);
while(t–)
{
long long int l,r;
scanf(“%lld%lld”,&l,&r);
if((l&1) && (r&1))
{
if((r-l) % 4 == 2)
printf(“Even\n”);
else
printf(“Odd\n”);
}
else if((l&1) && (r&1 == 0))
{
if((r-l+1) % 4 == 2)
printf(“Odd\n”);
else
printf(“Even\n”);
}
else if((l&1 == 0) && (r&1))
{
if((r-l+1) % 4 == 2)
printf(“Odd\n”);
else
printf(“Even\n”);
}
else
{
if((r-l) % 4 == 2)
printf(“Odd\n”);
else
printf(“Even\n”);
}
}
return 0;
}

Thanks.

Just count the number of odd numbers (cntO) between [l,r]. Thus, the answer is parity of cntO.
Have a Look : CodeChef: Practical coding for everyone

I got your logic.It’s correct. But I tried many test cases for my code.And it’s working also.But when i submit it’s giving wrong answer.Could you please provide me any test case where my code is failing.
Thanks.

One of the input for which your code fails is
3
5 6
8 9
4 9
Obviously, there are more.

when l = 5 and r = 6 it should enter in the second block of else if part and inside that since first condition ((r-l+1)%4 == 2) will be true for this case ,it should print Odd but it is printing Even. Correct me if I am wrong.
Thanks.