PROBLEM STATEMENT
Let us introduce a new operation called double xor, and use the operator ^^ to denote it. For two
integers A and B, A ^^ B is calculated as follows. Take the decimal representations of A and B.
If they have different lengths, prepend the shorter one with leading zeros until they both have
the same length. Then, label the digits of A as a1, a2, c, an (from left to right) and the
digits of B as b1, b2, ... , bn (from left to right). C = A ^^ B will consist of the digits c1,
c2, ... , cn (from left to right), where ci = (ai ^ bi) % 10, where ^ is the usual bitwise XOR
operator (see notes for exact definition) and x % y is the remainder of x divided by y. If C
happens to have any extra leading zeroes, they are ignored.
For example, 8765 ^^ 2309 = 462 (c1 = (8 ^ 2) % 10 = 10 % 10 = 0, c2 = (7 ^ 3) % 10 = 4 % 10 = 4,
c3 = (6 ^ 0) % 10 = 6 % 10 = 6, c4 = (5 ^ 9) % 10 = 12 % 10 = 2), and 5 ^^ 123 = 126 ("5" is
prepended with two leading zeros to become "005").
When multiple ^^ operations occur in an expression, they must be evaluated from left to right.
For example, A ^^ B ^^ C means (A ^^ B) ^^ C.
You are given an int N. Return the value of N ^^ (N - 1) ^^ (N - 2) ^^ c ^^ 1.
DEFINITION
Class:DoubleXor
Method:calculate
Parameters:int
Returns:int
Method signature:int calculate(int N)
NOTES
-If a and b are single bits then a ^ b is defined as (a + b) % 2. For two integers, A and B, in
order to calculate A ^ B, they need to be represented in binary: A = (an...a1)2, B = (bn...b1)2
(if the lengths of their representations are different, the shorter one is prepended with the
necessary number of leading zeroes). Then A ^ B = C = (cn...c1)2, where ci = ai ^ bi. For example,
10 ^ 3 = (1010)2 ^ (0011)2 = (1001)2 = 9.
CONSTRAINTS
-N will be between 1 and 1,000,000, inclusive.
EXAMPLES
0)
1
Returns: 1
This is simply 1.
1)
2
Returns: 3
2^^1=3
2)
7
Returns: 0
7^^6^^5^^4^^3^^2^^1=0
3)
10
Returns: 11
4)
102
Returns: 103
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.