here I am taking 3 inputs. 1st input will take test cases and the other two input will take starting and ending range. the program is running fine as expected but the limit of this question for compilation is 1 sec, and my code is taking 5.01 sec.
How can I make it more efficient so that I can submit the code?
The challenge was to take number of test cases.
Each test cases show take 2 input (starting and ending range) Eg: 1 4 (i.e 1,2,3,4)
Do the bitwise XOR operation for all of them (i.e 1^2^3^4)
Which when you perform will be equal to 4
Now just check if it is even or odd and print the same.
Here's my code:
from sys import stdin, stdout t = stdin.readline() for i in range(int(t)): p = 0 a, b = map(int,stdin.readline().split()) for x in range(a,b+1): p ^= int(x) if p % 2 == 0: stdout.write(str("Even\n")) else: stdout.write(str("Odd\n"))
compiling in python 3.6
INPUT: 4 1 4 2 6 3 3 2 3 OUTPUT: Even Even Odd Odd
Working perfectly with no issue in code.