Statistics

Problem Statement for "CoolNumber"

Problem Statement

Let's call a given number cool if its digits can be divided into two sets such that the sum of the digits in one set is equal to the sum of the digits in the other set. For example, the number 242 is cool because we can divide it into sets {2, 2} and {4}, and the sum of the digits in each set is 4. Given two ints A and B, return how many numbers between A and B, inclusive, are cool.

Definition

Class:
CoolNumber
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int A, int B)
(be sure your method is public)

Constraints

  • A will be between 1 and 109, inclusive.
  • B will be between A and 109, inclusive.
  • The difference between B and A will be at most 106.

Examples

  1. 1

    50

    Returns: 4

    Here we've got following cool numbers: 11, 22, 33, 44.

  2. 1

    1000

    Returns: 135

  3. 6354

    234363

    Returns: 82340

  4. 1

    1000000

    Returns: 376413

  5. 123

    123

    Returns: 1

  6. 1000000

    1000000

    Returns: 0

  7. 999999

    999999

    Returns: 1

  8. 1234

    563463

    Returns: 216272

  9. 12345

    123456

    Returns: 35380

  10. 123456

    987654

    Returns: 335021

  11. 111111

    222222

    Returns: 45711

  12. 111111

    111111

    Returns: 1

  13. 5235

    634567

    Returns: 242734

  14. 111115

    111116

    Returns: 1

  15. 1

    111115

    Returns: 32928

  16. 1

    124124

    Returns: 38467

  17. 234

    674573

    Returns: 259579

  18. 1

    111111

    Returns: 32926

  19. 85674

    674585

    Returns: 233978

  20. 999000000

    1000000000

    Returns: 422568

  21. 423146564

    424146564

    Returns: 498066

  22. 888808888

    889808888

    Returns: 465045

  23. 111111111

    112111111

    Returns: 493725

  24. 123456789

    124456789

    Returns: 499873

  25. 764574645

    764635243

    Returns: 30228

  26. 943576874

    944576765

    Returns: 490115

  27. 563645744

    564645744

    Returns: 498094

  28. 987654321

    988654321

    Returns: 479770

  29. 253464534

    254464530

    Returns: 498836

  30. 111011111

    111011111

    Returns: 1

  31. 1

    1111

    Returns: 156


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: