Statistics

Problem Statement for "SubtractionGenerator"

Problem Statement

Michal's younger brother Jan is learning how to subtract. Michal would like to generate some non-trivial exercises for him.

You are given the int result. Find any one pair of integers x and y such that:

  • Both x and y are between 1 and 10^9, inclusive.
  • The difference x-y is exactly equal to result.
  • The number y has the same number of digits as result.
  • The number x has more digits than result.

Return the int[] {x, y}.

Definition

Class:
SubtractionGenerator
Method:
generate
Parameters:
int
Returns:
int[]
Method signature:
int[] generate(int result)
(be sure your method is public)

Notes

  • The return value should be a int[] with two elements: element 0 should be x and element 1 should be y.
  • A valid solution always exists.
  • Any valid solution will be accepted.

Constraints

  • result will be between 1 and 10^6, inclusive.

Examples

  1. 47

    Returns: {123, 76 }

    123 - 76 = 47 Make sure that your x has more digits than the result. For example, the output {95, 48} isn't valid: even though 95 - 48 = 47, 95 doesn't have more digits than 47. Also make sure that you return the bigger number first. The output {76, 123} would also get rejected.

  2. 853

    Returns: {1234, 381 }

  3. 1

    Returns: {10, 9 }

  4. 2

    Returns: {10, 8 }

  5. 3

    Returns: {10, 7 }

  6. 4

    Returns: {10, 6 }

  7. 5

    Returns: {10, 5 }

  8. 6

    Returns: {10, 4 }

  9. 7

    Returns: {10, 3 }

  10. 8

    Returns: {10, 2 }

  11. 9

    Returns: {10, 1 }

  12. 10

    Returns: {100, 90 }

  13. 11

    Returns: {100, 89 }

  14. 12

    Returns: {100, 88 }

  15. 19

    Returns: {100, 81 }

  16. 29

    Returns: {100, 71 }

  17. 31

    Returns: {100, 69 }

  18. 49

    Returns: {100, 51 }

  19. 50

    Returns: {100, 50 }

  20. 90

    Returns: {100, 10 }

  21. 93

    Returns: {103, 10 }

  22. 100

    Returns: {1000, 900 }

  23. 110

    Returns: {1000, 890 }

  24. 200

    Returns: {1000, 800 }

  25. 213

    Returns: {1000, 787 }

  26. 298

    Returns: {1000, 702 }

  27. 346

    Returns: {1000, 654 }

  28. 900

    Returns: {1000, 100 }

  29. 1000

    Returns: {10000, 9000 }

  30. 1092

    Returns: {10000, 8908 }

  31. 1096

    Returns: {10000, 8904 }

  32. 1456

    Returns: {10000, 8544 }

  33. 1510

    Returns: {10000, 8490 }

  34. 2659

    Returns: {10000, 7341 }

  35. 2952

    Returns: {10000, 7048 }

  36. 3510

    Returns: {10000, 6490 }

  37. 3980

    Returns: {10000, 6020 }

  38. 6053

    Returns: {10000, 3947 }

  39. 7335

    Returns: {10000, 2665 }

  40. 8556

    Returns: {10000, 1444 }

  41. 10000

    Returns: {100000, 90000 }

  42. 11402

    Returns: {100000, 88598 }

  43. 11772

    Returns: {100000, 88228 }

  44. 12409

    Returns: {100000, 87591 }

  45. 15199

    Returns: {100000, 84801 }

  46. 17471

    Returns: {100000, 82529 }

  47. 18432

    Returns: {100000, 81568 }

  48. 27965

    Returns: {100000, 72035 }

  49. 30527

    Returns: {100000, 69473 }

  50. 30874

    Returns: {100000, 69126 }

  51. 49337

    Returns: {100000, 50663 }

  52. 58485

    Returns: {100000, 41515 }

  53. 64579

    Returns: {100000, 35421 }

  54. 100000

    Returns: {1000000, 900000 }

  55. 100001

    Returns: {1000000, 899999 }

  56. 100010

    Returns: {1000000, 899990 }

  57. 110000

    Returns: {1000000, 890000 }

  58. 111810

    Returns: {1000000, 888190 }

  59. 124999

    Returns: {1000000, 875001 }

  60. 135054

    Returns: {1000000, 864946 }

  61. 266933

    Returns: {1000000, 733067 }

  62. 319892

    Returns: {1000000, 680108 }

  63. 490530

    Returns: {1000000, 509470 }

  64. 990000

    Returns: {1090000, 100000 }

  65. 999998

    Returns: {1099998, 100000 }

  66. 999999

    Returns: {1099999, 100000 }

  67. 1000000

    Returns: {10000000, 9000000 }

  68. 95

    Returns: {190, 95 }

    Make sure that your y has the same number of digits as the result. For example, the output {103, 8} isn't valid: even though 103 - 8 = 95, 8 doesn't have two digits.

  69. 91

    Returns: {101, 10 }


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: