
In a distant galaxy, a species' lineage is tracked using an infinite binary tree. The gender of each individual is determined by a simple set of genetic rules:
You are given n (a level in the tree, 1-indexed) and k (a position within that level, 1-indexed from left to right). Your task is to determine the gender of the individual at that specific position.
A single line containing two space-separated integers, n and k.
Print a single character, either 'M' or 'F', representing the gender of the individual at the specified location.
Level n of the tree contains 2^(n-1) individuals.
Building the tree or the string for a large n is not feasible due to memory and time constraints. The solution must use the recursive structure of the problem to work backwards from the target position to the root.
The first half of any level is an exact copy of the previous level. The second half of any level is an inverted copy of the previous level (M becomes F, F becomes M).
3 3
F
The tree develops as follows:
- Level 1: M
- Level 2: M F (from the root 'M')
- Level 3: (M F) (F M) (from the nodes 'M' and 'F' at level 2)
The 3rd individual at level 3 is 'F'.
1 1
M
The individual at level 1, position 1 is the root, which is 'M'.
The expected time complexity is O(n).
1 <= n <= 60
1 <= k <= 2^(n-1)
Time limit: 1 sec