PowerOfThreeEasy
SRM 604 · 2013-12-22 · by cgy4ever
SRM 604 · 2013-12-22 · by cgy4ever · Math
Problem Statement
Problem Statement
Fox Ciel has a robot.
The robot is located on an infinite plane.
At the beginning, the robot starts at the coordinates (0, 0).
The robot can then make several steps.
The steps are numbered starting from 0.
In each step, Ciel must choose one of two directions for the robot: right (x coordinate increases) or up (y coordinate increases). In step k, the robot will move 3^k units in the chosen direction. It is not allowed to skip a step.
You are givenint s x and y.
Return "Possible" (quotes for clarity) if it is possible that the robot reaches the point (x,y) after some (possibly zero) steps.
Otherwise, return "Impossible".
In each step, Ciel must choose one of two directions for the robot: right (x coordinate increases) or up (y coordinate increases). In step k, the robot will move 3^k units in the chosen direction. It is not allowed to skip a step.
You are given
Constraints
- x will be between 0 and 1,000,000,000, inclusive.
- y will be between 0 and 1,000,000,000, inclusive.
Examples
0)
1 3 Returns: "Possible"
In step 0 Ciel will send the robot right to (1,0). In step 1 she will send it up to (1,3).
1)
1 1 Returns: "Impossible"
2)
3 0 Returns: "Impossible"
3)
1 9 Returns: "Impossible"
Note that it is not allowed to move the robot right in step 0, skip step 1, and then move the robot up in step 2.
4)
3 10 Returns: "Possible"
Submissions are judged against all 155 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class PowerOfThreeEasy with a public method string ableToGet(int x, int y) · 155 test cases · 2 s / 256 MB per case