TopcoderArchiveVisit Topcoder
SRM22 Dec 2013
SRM 620

PairGameEasy

Problem statement, definition, constraints, and public examples.

Problem Statement

You have an ordered pair of integers. You can now make zero or more steps. In each step, you can change your pair into a new pair of integers by adding one of them to the other. That is, if your current pair is (x, y), then your next pair will be either (x+y, y), or (x, x+y).


For example, you can start with (1, 2), change it to (3, 2), change that to (3, 5), and then change that again to (3, 8).


You are given four ints: a, b, c, and d. Return "Able to generate" (quotes for clarity) if it is possible to start with the pair (a, b) and end with the pair (c, d). Otherwise, return "Not able to generate".

Definition

Class:
PairGameEasy
Method:
able
Parameters:
int, int, int, int
Returns:
String
Method signature:
String able(int a, int b, int c, int d)
(be sure your method is public)

Constraints

  • a will be between 1 and 1,000, inclusive.
  • b will be between 1 and 1,000, inclusive.
  • c will be between 1 and 1,000, inclusive.
  • d will be between 1 and 1,000, inclusive.

Examples

  1. 1
    2
    3
    5
    Returns: "Able to generate"
    (1, 2) -> (3, 2) -> (3, 5).
  2. 1
    2
    2
    1
    Returns: "Not able to generate"
    Note that order matters: (1, 2) and (2, 1) are two different pairs.
  3. 2
    2
    2
    999
    Returns: "Not able to generate"
  4. 2
    2
    2
    1000
    Returns: "Able to generate"
  5. 47
    58
    384
    221
    Returns: "Able to generate"
  6. 1000
    1000
    1000
    1000
    Returns: "Able to generate"
Back to all problems