Problem Statement
Little Elephant from the Zoo of Lviv likes integers.
You are given three
Definition
- Class:
- LittleElephantAndXor
- Method:
- getNumber
- Parameters:
- int, int, int
- Returns:
- long
- Method signature:
- long getNumber(int A, int B, int C)
- (be sure your method is public)
Notes
- XOR (exclusive or) is a binary operation, performed on two numbers in binary notation. First, the shorter number is prepended with leading zeroes until both numbers have the same number of digits (in binary). Then, the result is calculated as follows: for each bit where the numbers differ the result has 1 in its binary representation. It has 0 in all other positions.
- For example 42 XOR 7 is performed as follows. First, the numbers are converted to binary: 42 is 101010 and 7 is 111. Then the shorter number is prepended with leading zeros until both numbers have the same number of digits. This means 7 becomes 000111. Then 101010 XOR 000111 = 101101 (the result has ones only in the positions where the two numbers differ). Then the result can be converted back to decimal notation. In this case 101101 = 45, so 42 XOR 7 = 45.
Constraints
- A, B and C will each be between 1 and 1,000,000,000 (109), inclusive.
Examples
2
2
1
Returns: 5
There are 9 possible pairs in this case: 0 XOR 0 = 0 0 XOR 1 = 1 0 XOR 2 = 2 1 XOR 0 = 1 1 XOR 1 = 0 1 XOR 2 = 3 2 XOR 0 = 2 2 XOR 1 = 3 2 XOR 2 = 0 Among them, only 5 have XOR less than or equal to 1. Note that (0,1) and (1,0) are two different pairs.
4
7
3
Returns: 20
10
10
5
Returns: 57
774
477
447
Returns: 214144
1000000000
1000000000
500000000
Returns: 468566946385621507
458795402
684548754
1
Returns: 917590806
1000000000
1000000000
74
Returns: 75000000001
1000000000
1000000000
487598545
Returns: 457079997272772517
1000000000
1000000000
10
Returns: 11000000001
1000000000
1000000000
100
Returns: 101000000001
1000000000
1000000000
1000
Returns: 1000999750611
1000000000
1000000000
1000000
Returns: 999776121957507
1000000000
1000000000
10000000
Returns: 9977667558462723
1000000000
999999999
4587455
Returns: 4582484343704064
999999999
999999997
1
Returns: 1999999996
695574
487545895
45875774
Returns: 31910042195625
174094883
455171153
761423222
Returns: 79242969255776136
685761893
795431234
411387428
Returns: 259359244590272434
793198651
286024866
90061390
Returns: 25759797382609997
344606619
496378830
135984077
Returns: 46861013493396360
361542098
372601658
541200147
Returns: 134711185885742241
71777734
599818267
38012510
Returns: 2728451941242585
478351202
640618985
143988088
Returns: 68876875590821067
783837108
349651100
484993
Returns: 169578686078394
553337439
88068199
282891
Returns: 24913789234400
781586125
258626540
182120
Returns: 47101324273461
762952004
918195326
677230
Returns: 516694749298155
419698256
491250840
799770
Returns: 335662494699147
357665826
441616336
825362
Returns: 295204139970201
862146292
503649294
596343
Returns: 300348235177480
581258
442931
8730383
Returns: 257458211388
372976
211326
1222641
Returns: 78820110479
400532
500455
6482169
Returns: 200449143048
849208
705674
9265775
Returns: 599265561075
830224
554027
1117301
Returns: 459967896300
12904
770894
4783711
Returns: 9948399975
450146
356668
7191628
Returns: 160553480343
999999999
1000000000
275484584
Returns: 260607706026806697
999999998
999999097
354875965
Returns: 334144367716115668
900000009
800000008
700000007
Returns: 485941141015817970
1
1
1000000000
Returns: 4
43214423
43214423
33434
Returns: 1444684709440
1000000000
11111111
11111111
Returns: 123456809876544
10000000
10000000
500000000
Returns: 100000020000001
1000000000
1000000000
1000000000
Returns: 931696035385621507
234543554
34543
3464562
Returns: 119679864272