Stone Groups
InterviewTime limit2sMemory limit512 MB
Starting from stone counts A, B, C, repeatedly double the smaller of two unequal groups and subtract it from the larger; decide whether all three can become equal.
- Level
Medium6 of 10
- Topics
- BFS, Math, Hash map, Simulation
- Solved
- No attempts yet
Problem
Kangho plays a game with stones. The stones sit in three groups holding , and stones. Kangho wants all three groups to hold the same number of stones.
He moves stones one step at a time, and a step works like this.
- Pick two groups whose stone counts differ.
- Call the smaller count and the larger count .
- Change the smaller group to stones and the larger group to stones.
Write a program that prints 1 if repeating the step any number of times can make the three groups hold the same number of stones, and 0 otherwise.
Input
The first line contains , and separated by spaces. ()
Output
Print 1 if the three groups can be made to hold the same number of stones, and 0 otherwise.