Statistics

Problem Statement for "RepeatedAddition"

Problem Statement

Repeated addition is a tedious task in which an integer A is first written on a piece of paper with a plain pencil, and then the integer X is repeatedly added to the number on paper until that number becomes B.

Only one number is written on the paper at any given time. Addition is performed so that only digits that need changing are erased and replaced by new ones.

In order to estimate how many erasers will be needed, return the total number of digits erased if repeated addition is performed as above. The three integers will be given as three Strings.

Definition

Class:
RepeatedAddition
Method:
digitsErased
Parameters:
String, String, String
Returns:
long
Method signature:
long digitsErased(String A, String B, String X)
(be sure your method is public)

Notes

  • New digits may only be added to the left of the number already written (see example 5).

Constraints

  • A, B and X will represent integers between 1 and 10^16, inclusive.
  • A, B and X will not have leading zeroes.
  • A will be less than B.
  • (B-A) will be divisible by X.

Examples

  1. "2"

    "6"

    "1"

    Returns: 4

    We start with the number 2. Adding 1 repeatedly gives the numbers 3, 4, 5 and 6. Every time we add 1 we need to erase the digit that was previously written, amounting to 4 erasures.

  2. "88"

    "107"

    "19"

    Returns: 2

    Only one addition is performed. The two 8 digits must be erased and replaced by 0 and 7.

  3. "12345"

    "64901"

    "7508"

    Returns: 32

  4. "123"

    "843"

    "120"

    Returns: 12

  5. "224"

    "6059999999999618"

    "909"

    Returns: 25466666666639

  6. "3"

    "811"

    "404"

    Returns: 4

  7. "1"

    "10000000000000000"

    "1"

    Returns: 11111111111111094

  8. "90313261712060"

    "4891640535944272"

    "54982"

    Returns: 418368414862

  9. "433942766076535"

    "9140483029804567"

    "108504"

    Returns: 430974705953

  10. "935904549874427"

    "8687977631107012"

    "29603"

    Returns: 1054259476607

  11. "634426934866256"

    "1511475059061890"

    "1"

    Returns: 974497915772927

  12. "975672979948359"

    "7805760303969847"

    "8"

    Returns: 1612659507060630

  13. "360662004287526"

    "8889969161072941"

    "656100550521955"

    Returns: 170

  14. "2030868398102664"

    "3922636999501992"

    "26274563908324"

    Returns: 1010

  15. "1"

    "10000000000000000"

    "9999999999999999"

    Returns: 1

  16. "1"

    "100001"

    "100000"

    Returns: 0

  17. "1745006524075"

    "9082677070912566"

    "9080932064388491"

    Returns: 12

  18. "21397914118602"

    "1025959971674319"

    "1004562057555717"

    Returns: 12

  19. "83161550039518"

    "3052127076665850"

    "2968965526626332"

    Returns: 13

  20. "587926429850541"

    "4391630035003284"

    "69221"

    Returns: 304870089982

  21. "547238262383620"

    "5721977029360720"

    "94"

    Returns: 145577757274295

  22. "5"

    "9343895873501220"

    "1868779174700243"

    Returns: 58

  23. "640938"

    "406287062207522"

    "101571765391646"

    Returns: 48

  24. "73"

    "962400308002063"

    "96240030800199"

    Returns: 89

  25. "3075314563"

    "6207637909678305"

    "3103817417181871"

    Returns: 25

  26. "5"

    "5897719843262005"

    "62521000"

    Returns: 537189311

  27. "29528293481"

    "669824456768360"

    "9"

    Returns: 148843317438855

  28. "6"

    "384078811921602"

    "192039405960798"

    Returns: 13

  29. "241771570256"

    "9091150862479346"

    "9090909090909090"

    Returns: 10

  30. "99642281998123"

    "1008733191089032"

    "909090909090909"

    Returns: 13

  31. "422420753742282"

    "7695148026469554"

    "909090909090909"

    Returns: 116

  32. "9579339811"

    "1941681299062767"

    "194"

    Returns: 28179817513040

  33. "4"

    "7000000000061604"

    "700"

    Returns: 17777777777918

  34. "316066770424842"

    "9376067645790264"

    "906"

    Returns: 35466670093407

  35. "14455959161367"

    "9840027884919879"

    "869407"

    Returns: 70735951173

  36. "909928898277110"

    "7990813338468737"

    "39013"

    Returns: 825914625692

  37. "470004032340001"

    "2803625699115961"

    "99"

    Returns: 51858259261682

  38. "635481661125235"

    "7472170553220649"

    "6"

    Returns: 1899080247804280

  39. "946298655551348"

    "5238301320803129"

    "1"

    Returns: 4768891850279759

  40. "96697108711701"

    "8050550269911064"

    "98221"

    Returns: 426698939956

  41. "773102570750609"

    "8045829843477881"

    "909090909090909"

    Returns: 118

  42. "290119691183936"

    "4407339493972292"

    "1029304950697089"

    Returns: 50

  43. "93376390157799"

    "7021967974687722"

    "989798797789989"

    Returns: 74

  44. "2043601634821768"

    "4274721675435952"

    "3653414"

    Returns: 4522764117

  45. "12"

    "123"

    "111"

    Returns: 2


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: