PairGameEasy
SRM 620 · 2013-12-22 · by cgy4ever
SRM 620 · 2013-12-22 · by cgy4ever · Brute Force
Problem Statement
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 fourint s: 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".
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
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
0)
1 2 3 5 Returns: "Able to generate"
(1, 2) -> (3, 2) -> (3, 5).
1)
1 2 2 1 Returns: "Not able to generate"
Note that order matters: (1, 2) and (2, 1) are two different pairs.
2)
2 2 2 999 Returns: "Not able to generate"
3)
2 2 2 1000 Returns: "Able to generate"
4)
47 58 384 221 Returns: "Able to generate"
Submissions are judged against all 115 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class PairGameEasy with a public method string able(int a, int b, int c, int d) · 115 test cases · 2 s / 256 MB per case