Moo Game
InterviewTime limit1sMemory limit128 MB
Given N up to 1e9, report whether the N-th character of the recursively defined Moo sequence is 'm' or 'o'.
- Level
Medium6 of 10
- Topics
- Recursion, Divide and conquer, Math, Implementation
- Solved
- No attempts yet
Problem
Moo is a game that several people can enjoy together: the players take turns shouting the characters of the Moo sequence, one character each, in order.
The Moo sequence is an infinite string that begins like this:
m o o m o o o m o o m o o o o m o o m o o o m o o m o o o o o
The Moo sequence is defined recursively. First, let be the length-3 string moo. For every , is formed by taking , then appending the string made of a single m followed by copies of o (that is, m followed by os), and then appending again.
S(0) = "m o o"
S(1) = "m o o m o o o m o o"
S(2) = "m o o m o o o m o o m o o o o m o o m o o o m o o"
Repeating this process yields an infinite string, which is called the Moo sequence.
Given an integer , write a program that finds the -th character of the Moo sequence (characters are counted starting from 1).
Input
The first line contains an integer ().
Output
Print the -th character of the Moo sequence (either m or o).