Define a sequence of natural number , where is any natural number, in which each digit of is either or , by the following rules:
We define as a natural number, which can be obtained by replacing the digits of with if the digit is , and with if the digit is .
For example, , , , and so on.
is defined as the number of digits in .
is defined as the number of times appears in .
For example, , , , , and so on.
What is ?
Note: There have been slight edits to the original question. The original question asks for a general formula of and . Therefore, to provide for a numerical answer, the edits are necessary.
This algebra problem appears in the anime Puella Magi Madoka Magica. Students attending the Math class are just 14 years old, yet they are expected to solve the following question on the spot!
Translation credits: Puella Magi Wiki.
This problem is part of the question set Mathematics in Anime.