TopcoderArchive
SRM17 Feb 2022
SRM 824

SubtractionGenerator

Problem statement, definition, constraints, and public examples.

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. 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.
Back to all problems