Statistics

Problem Statement for "CoolNumbers"

Problem Statement

A cool number is a non-negative integer that contains at least three consecutive ones or three consecutive zeroes in its binary representation (without leading zeroes). For example, 8 (1000 binary) and 15 (1111 binary) are cool numbers, but 27 (11011 binary) is not.

Return the number of cool numbers between lowerBound and upperBound, inclusive.

Definition

Class:
CoolNumbers
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int lowerBound, int upperBound)
(be sure your method is public)

Constraints

  • upperBound will be between 0 and 2147483647, inclusive.
  • lowerBound will be between 0 and upperBound, inclusive.

Examples

  1. 0

    16

    Returns: 5

    Following numbers between 0 and 16, inclusive are cool: 7 (111 binary) 8 (1000 binary) 14 (1110 binary) 15 (1111 binary) 16 (10000 binary)

  2. 17

    100

    Returns: 49

  3. 2000000000

    2100000000

    Returns: 100000001

  4. 2

    6

    Returns: 0

  5. 0

    2147483647

    Returns: 2141780762

  6. 99233264

    1450887072

    Returns: 1347886445

  7. 2083801942

    2086929383

    Returns: 3127442

  8. 29085184

    1341285414

    Returns: 1308479235

  9. 382973448

    1507907848

    Returns: 1122106940

  10. 1070357791

    1587246305

    Returns: 515542246

  11. 1355980396

    2009442025

    Returns: 651797550

  12. 216672149

    512996289

    Returns: 295370708

  13. 433467937

    1415084057

    Returns: 979362787

  14. 361487870

    1509019540

    Returns: 1144549979

  15. 1259854638

    1952435843

    Returns: 690645683

  16. 103553592

    2131534667

    Returns: 2022988836

  17. 1535604989

    1810766776

    Returns: 274526166

  18. 928468566

    1359905363

    Returns: 430922569

  19. 543553380

    796638146

    Returns: 252252727

  20. 26688227

    337023359

    Returns: 309074835

  21. 738600026

    1660190625

    Returns: 919533684

  22. 6668117

    192050721

    Returns: 184340617

  23. 900787359

    1876147816

    Returns: 973049810

  24. 637126021

    2127645589

    Returns: 1487191409

  25. 29944912

    233675245

    Returns: 202701876

  26. 509637919

    1844228275

    Returns: 1331065779

  27. 4972033

    662059271

    Returns: 654672909

  28. 267539403

    340122637

    Returns: 72386817

  29. 167060272

    724319023

    Returns: 555459749

  30. 89027760

    353727665

    Returns: 263711051

  31. 106476229

    1807977682

    Returns: 1696727524

  32. 457046166

    1214008264

    Returns: 755569462

  33. 397376583

    799246718

    Returns: 400720285

  34. 1734144407

    1751936664

    Returns: 17792258

  35. 59121554

    2081587070

    Returns: 2017276859

  36. 0

    2000000000

    Returns: 1994297115

  37. 0

    2100000000

    Returns: 2094297115

  38. 0

    46

    Returns: 19

  39. 324

    2147483647

    Returns: 2141780539

  40. 200

    2100000000

    Returns: 2094296990

  41. 0

    2147483647

    Returns: 2141780762

  42. 123456789

    2134567890

    Returns: 2006240255


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: