longlongsumxor(longlong N){ longlong ans = 0; for (longlong i = 0; i < N; i++) { if ((N ^ i) == (N + i))ans++; } return ans; }
Python:
defsumxor(N) : ans = 0 for i in range(N) : if ((N ^ i) == (N + i)) : ans += 1 return ans
Java:
publicstaticlongsumxor(long N){ long ans = 0; for (long i = 0; i < N; i++) { if ((N ^ i) == (N + i)) ans++; } return ans; }
Pascal:
var i, N: int64; ans : int64 = 0; functionsumxor(N: int64):int64; begin ans:=0; for i := 0to N dobegin if ((N xor i) = (N + i)) then ans:=ans+1; if (N=0) ans:=0; sumxor:=ans; end; end;