Color Change of Go Stones
InterviewTime limit1sMemory limit128 MB
Repeat k times the rule that replaces each circular gap with the xor of its two neighbors, then count the white stones.
- Level
Easy3 of 10
- Topics
- Simulation, Array
- Solved
- No attempts yet
Problem
A box holds plenty of black and white Go stones. Take stones out of the box. The stones taken out first are all white and the rest are all black. Lay all stones around a circle at even spacing, in the order they came out.
Next, look at the colors on that circle and take new stones from the box to build a new circle. Go around the circle once and place one new stone in each gap between two neighboring stones, by these rules.
- Between two white stones, place a black stone.
- Between a white stone and a black stone, place a white stone.
- Between two black stones, place a black stone.
- Between a black stone and a white stone, place a white stone.
There are gaps, so the new circle holds stones as well. Once every new stone is in place, remove all original stones. That is one repetition, and the circle that remains goes through the same process again.
Find how many white stones are on the circle after the -th repetition.
The picture below shows the case , , . From the left: the starting circle, the circle after the first repetition, and the circle after the second repetition.

and are natural numbers with and . satisfies .
Input
Each line holds one group of data. A line has the natural numbers , , separated by single commas, with no spaces. The line after the last group holds -1, which marks the end of the input.
Output
Print one line for each group of data. A line starts with the input data written back in the form n,m,k, then a colon and one space, then the number of white stones.