XORIER- Need Help with my approach

The question is XORIER .

My submission which fails test cases: XORIER - WA

MY approach : I figured out that only two even number or two odd number can have even XOR, which will be equal to sum of two prime number with same parity.

There will be two corner cases i.e. when XOR becomes 0 or 2.
To remove zero, I used SET data type, so that there won’t be any duplicates, but doing so i was unable to use set to remove 2nd corner case, that’s why i took help of array. Two number having XOR as 2 will always be at a difference of 2 and 1 if the number is missing in the sorted array. I removed such pairs by doing count–; .

For total number of even number, the total pair having even XOR is (n*(n+1))/2-n and same for odd numbers.

I took different test cases, but i couldn’t figure it out, what’s wrong.
Please tell me what am I doing wrong?

(And is there any way in which i wouldn’t had to use array and do it only with set?)

Please Help!!

Tank you!!!