Movement 3
InterviewTime limit2sMemory limit512 MB
Decide whether (x, y) is reachable by moving 3^k right or up on each step k, starting at the origin.
- Level
Medium5 of 10
- Topics
- Math, Bit manipulation, Recursion
- Solved
- No attempts yet
Problem
Donghyuk stands at the origin of an infinitely large plane.
He moves toward one step at a time. Steps are numbered from , and the number goes up by after each finished step.
On step he picks one of two directions, right (the direction in which grows) or up (the direction in which grows), and moves exactly in the direction he picked. He cannot stay in place and he cannot skip a step.
Once he arrives at he stops there. Given and , write a program that decides whether he can reach starting from .
Input
The first line contains and , separated by a space. (, )
Output
Print if can be reached from , and otherwise.