Statistics

Problem Statement for "SumOfLuckiness"

Problem Statement

Mr. Dengklek once told you that 4 and 7 are lucky numbers. He also defined the luckiness of a positive integer as the absolute difference between the number of 7s in its decimal representation and the number of 4s in its decimal representation. For example, for each of the numbers 23, 47 and 47714 the luckiness is 0, and for each of the numbers 4474 and 7070 the luckiness is 2.

You are given two ints A and B. Return the sum of luckiness of all integers between A and B, inclusive.

Definition

Class:
SumOfLuckiness
Method:
theSum
Parameters:
int, int
Returns:
long
Method signature:
long theSum(int A, int B)
(be sure your method is public)

Constraints

  • A will be between 1 and 2,000,000,000, inclusive.
  • B will be between A and 2,000,000,000, inclusive.

Examples

  1. 1

    10

    Returns: 2

    The luckiness of 4 is 1. The luckiness of 7 is 1. The luckiness of the other numbers is 0. So, the sum of luckiness is 2.

  2. 40

    47

    Returns: 8

    The luckiness of 40, 41, 42, 43, 45, and 46 is 1. The luckiness of 44 is 2. The luckiness of 47 is 0.

  3. 58

    526

    Returns: 231

  4. 4444

    7777

    Returns: 2338

  5. 585858585

    858585858

    Returns: 287481025

  6. 1

    1

    Returns: 0

  7. 1

    2000000000

    Returns: 2008249560

  8. 2000000000

    2000000000

    Returns: 0

  9. 7

    7

    Returns: 1

  10. 4

    4

    Returns: 1

  11. 4

    7

    Returns: 2

  12. 4

    1000

    Returns: 492

  13. 12345

    1234567890

    Returns: 1221528868

  14. 2000000

    2000000000

    Returns: 2006673768

  15. 1819245736

    2000000000

    Returns: 170834843

  16. 100

    526

    Returns: 215

  17. 777777777

    1777777777

    Returns: 1004124789

  18. 444444444

    1444444444

    Returns: 1004124789

  19. 444444444

    777777777

    Returns: 353825136

  20. 893274

    1324238943

    Returns: 1305462848

  21. 23

    433

    Returns: 174

  22. 333333333

    999999999

    Returns: 694239930

  23. 184382

    323462173

    Returns: 301221058

  24. 111111

    444444

    Returns: 256884

  25. 44

    44

    Returns: 2

  26. 77

    77

    Returns: 2

  27. 777777777

    877777777

    Returns: 102846195

  28. 444444444

    544444444

    Returns: 108830474

  29. 100

    156

    Returns: 19

  30. 45634

    23456443

    Returns: 20005740

  31. 99

    9999

    Returns: 6004

  32. 3467

    24567918

    Returns: 21209422

  33. 7

    9

    Returns: 1

  34. 927388

    937354

    Returns: 5996

  35. 934345834

    962817335

    Returns: 28249479

  36. 8712

    923473

    Returns: 726150

  37. 188888

    818394

    Returns: 525145

  38. 1

    2

    Returns: 0

  39. 1

    1999999996

    Returns: 2008249559

  40. 3

    2000000000

    Returns: 2008249560

  41. 1

    1999999997

    Returns: 2008249560

  42. 2

    1999999999

    Returns: 2008249560

  43. 13

    100000000

    Returns: 93769774

  44. 1

    199999999

    Returns: 187539552


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: