Statistics

Problem Statement for "DivisibleByDigits"

Problem Statement

Given an integer n, find the smallest integer that starts with n and is divisible by every non-zero digit of n (all in decimal notation).

Definition

Class:
DivisibleByDigits
Method:
getContinuation
Parameters:
int
Returns:
long
Method signature:
long getContinuation(int n)
(be sure your method is public)

Notes

  • An integer A starts with an integer B if the string representation of B is a prefix of the string representation of A (both in decimal notation with no leading zeroes).

Constraints

  • n will be between 1 and 1000000000, inclusive.

Examples

  1. 13

    Returns: 132

    We need a number that starts with 13 and is divisible by 1 (always true) and by 3. The smallest one is 132.

  2. 648

    Returns: 648

    If n is divisible by all its non-zero digits, the answer to the problem is n itself.

  3. 566

    Returns: 56610

    The resulting number must be divisible by 5, so it should end either with 0 or with 5. But a number ending with 5 is odd and can't be divisible by 6. So the last digit of the answer must be 0. In order to make the number divisible by 6, we need to put something before this 0, and the smallest appropriate digit is 1.

  4. 308

    Returns: 30816

  5. 191

    Returns: 1917

  6. 1000000000

    Returns: 1000000000

  7. 64348557

    Returns: 64348557000

  8. 987654321

    Returns: 987654321360

  9. 123456789

    Returns: 1234567890360

  10. 1

    Returns: 1

  11. 2

    Returns: 2

  12. 9

    Returns: 9

  13. 10

    Returns: 10

  14. 12

    Returns: 12

  15. 14

    Returns: 140

  16. 17

    Returns: 175

  17. 74

    Returns: 7420

  18. 98

    Returns: 9864

  19. 108

    Returns: 1080

  20. 345

    Returns: 34500

  21. 397

    Returns: 39753

  22. 491

    Returns: 49104

  23. 777

    Returns: 777

  24. 1078

    Returns: 107800

  25. 1245

    Returns: 124500

  26. 1279

    Returns: 1279026

  27. 1583

    Returns: 1583040

  28. 1759

    Returns: 1759275

  29. 1765

    Returns: 1765050

  30. 7185

    Returns: 7185080

  31. 7298

    Returns: 7298424

  32. 23497

    Returns: 23497236

  33. 47259

    Returns: 472590720

  34. 5789

    Returns: 57891960

  35. 7589

    Returns: 75892320

  36. 19758

    Returns: 197580600

  37. 28759

    Returns: 287592480

  38. 44957

    Returns: 449570520

  39. 200508709

    Returns: 2005087092120

  40. 314159265

    Returns: 31415926500

  41. 314167958

    Returns: 3141679582440

  42. 314169578

    Returns: 3141695781000

  43. 464597508

    Returns: 4645975080600

  44. 464597517

    Returns: 4645975170060

  45. 504604188

    Returns: 5046041880

  46. 604070913

    Returns: 6040709136

  47. 704060432

    Returns: 70406043204

  48. 774378549

    Returns: 774378549000

  49. 812341512

    Returns: 8123415120

  50. 825473880

    Returns: 825473880

  51. 833330001

    Returns: 8333300016

  52. 833333759

    Returns: 8333337592440

  53. 844444597

    Returns: 8444445972480

  54. 931394757

    Returns: 9313947570060

  55. 934330293

    Returns: 93433029300

  56. 999252999

    Returns: 9992529990

  57. 999585999

    Returns: 999585999000

  58. 999909999

    Returns: 999909999

  59. 999999991

    Returns: 9999999918

  60. 999999992

    Returns: 99999999216

  61. 999999997

    Returns: 99999999729

  62. 999999999

    Returns: 999999999

  63. 83

    Returns: 8304

  64. 346258971

    Returns: 3462589710720

  65. 907678453

    Returns: 9076784532480

  66. 56789

    Returns: 567892080

  67. 147

    Returns: 14700

  68. 950030021

    Returns: 95003002170

  69. 782343

    Returns: 782343072

  70. 999999750

    Returns: 999999750015

  71. 310

    Returns: 3102

  72. 234567890

    Returns: 2345678901720

  73. 21

    Returns: 210

  74. 19

    Returns: 198

  75. 6214

    Returns: 62148

  76. 27

    Returns: 2702

  77. 999000587

    Returns: 9990005870880

  78. 9010

    Returns: 90108

  79. 77996611

    Returns: 7799661198

  80. 19783465

    Returns: 197834651280

  81. 25

    Returns: 250

  82. 987577770

    Returns: 9875777700600

  83. 334

    Returns: 3348

  84. 927316845

    Returns: 927316845000

  85. 58

    Returns: 5800

  86. 46

    Returns: 468

  87. 925483158

    Returns: 92548315800

  88. 752752752

    Returns: 75275275250


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: