#K81917. Magical String Sequence
Magical String Sequence
Magical String Sequence
You are given a positive integer ( n ). Your task is to generate the ( n^{th} ) term of the Magical String Sequence, which is defined similarly to the classic count-and-say sequence. The sequence is generated as follows:
- The first term is "1".
- Each subsequent term is generated by reading the previous term and describing it in terms of the number of consecutive digits. For example, the term "1211" is read off as "one 1, one 2, and two 1s", so the next term becomes "111221".
For example: [ \begin{aligned} \text{Term 1: } & 1 \ \text{Term 2: } & 11 \ \text{Term 3: } & 21 \ \text{Term 4: } & 1211 \ \text{Term 5: } & 111221 \ \end{aligned} ]
Your program should read the integer ( n ) from standard input and output the corresponding magical string to standard output.
inputFormat
The input consists of a single integer ( n ) (1 ≤ ( n ) ≤ some reasonable limit), provided via standard input.
outputFormat
Output the ( n^{th} ) term of the Magical String Sequence as a string to standard output.## sample
1
1