Statistics

Problem Statement for "LittleElephantAndXor"

Problem Statement

Little Elephant from the Zoo of Lviv likes integers.

You are given three ints A, B and C. Return the number of ordered pairs (X,Y) of integers such that 0 <= X <= A, 0 <= Y <= B, and the value (X XOR Y) is less than or equal to C.

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

  1. 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.

  2. 4

    7

    3

    Returns: 20

  3. 10

    10

    5

    Returns: 57

  4. 774

    477

    447

    Returns: 214144

  5. 1000000000

    1000000000

    500000000

    Returns: 468566946385621507

  6. 458795402

    684548754

    1

    Returns: 917590806

  7. 1000000000

    1000000000

    74

    Returns: 75000000001

  8. 1000000000

    1000000000

    487598545

    Returns: 457079997272772517

  9. 1000000000

    1000000000

    10

    Returns: 11000000001

  10. 1000000000

    1000000000

    100

    Returns: 101000000001

  11. 1000000000

    1000000000

    1000

    Returns: 1000999750611

  12. 1000000000

    1000000000

    1000000

    Returns: 999776121957507

  13. 1000000000

    1000000000

    10000000

    Returns: 9977667558462723

  14. 1000000000

    999999999

    4587455

    Returns: 4582484343704064

  15. 999999999

    999999997

    1

    Returns: 1999999996

  16. 695574

    487545895

    45875774

    Returns: 31910042195625

  17. 174094883

    455171153

    761423222

    Returns: 79242969255776136

  18. 685761893

    795431234

    411387428

    Returns: 259359244590272434

  19. 793198651

    286024866

    90061390

    Returns: 25759797382609997

  20. 344606619

    496378830

    135984077

    Returns: 46861013493396360

  21. 361542098

    372601658

    541200147

    Returns: 134711185885742241

  22. 71777734

    599818267

    38012510

    Returns: 2728451941242585

  23. 478351202

    640618985

    143988088

    Returns: 68876875590821067

  24. 783837108

    349651100

    484993

    Returns: 169578686078394

  25. 553337439

    88068199

    282891

    Returns: 24913789234400

  26. 781586125

    258626540

    182120

    Returns: 47101324273461

  27. 762952004

    918195326

    677230

    Returns: 516694749298155

  28. 419698256

    491250840

    799770

    Returns: 335662494699147

  29. 357665826

    441616336

    825362

    Returns: 295204139970201

  30. 862146292

    503649294

    596343

    Returns: 300348235177480

  31. 581258

    442931

    8730383

    Returns: 257458211388

  32. 372976

    211326

    1222641

    Returns: 78820110479

  33. 400532

    500455

    6482169

    Returns: 200449143048

  34. 849208

    705674

    9265775

    Returns: 599265561075

  35. 830224

    554027

    1117301

    Returns: 459967896300

  36. 12904

    770894

    4783711

    Returns: 9948399975

  37. 450146

    356668

    7191628

    Returns: 160553480343

  38. 999999999

    1000000000

    275484584

    Returns: 260607706026806697

  39. 999999998

    999999097

    354875965

    Returns: 334144367716115668

  40. 900000009

    800000008

    700000007

    Returns: 485941141015817970

  41. 1

    1

    1000000000

    Returns: 4

  42. 43214423

    43214423

    33434

    Returns: 1444684709440

  43. 1000000000

    11111111

    11111111

    Returns: 123456809876544

  44. 10000000

    10000000

    500000000

    Returns: 100000020000001

  45. 1000000000

    1000000000

    1000000000

    Returns: 931696035385621507

  46. 234543554

    34543

    3464562

    Returns: 119679864272


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)2024, TopCoder, Inc. All rights reserved.
This problem was used for: