#K76932. Fibonacci String Permutations
Fibonacci String Permutations
Fibonacci String Permutations
In this problem, you are given an integer k and another integer p. First, generate the Fibonacci String Fk defined recursively as follows:
\( F(1)=a, \quad F(2)=b, \quad F(n)=F(n-1)+F(n-2) \text{ for } n \ge 3. \)
Once the Fibonacci String Fk is obtained, consider all of its permutations (treating each character instance as distinct even if some characters are equal) sorted in lexicographical order. Your task is to output the p-th permutation in this order.
Note: The positions are 1-indexed. For example, when k = 4, F(4) = "bab". Its full list of permutations (including duplicates) when sorted lexicographically is:
abb abb bab bab bba bba
So, if p = 1 the answer is "abb", if p = 3 the answer is "bab", and if p = 6 the answer is "bba".
inputFormat
The input consists of a single line containing two space‐separated integers:
k
— the order of the Fibonacci string.p
— the index (1-indexed) of the desired permutation in lexicographical order.
You should read from standard input.
outputFormat
Output a single line containing the p-th lexicographically smallest permutation of the Fibonacci string Fk.
The result should be printed to standard output.
## sample1 1
a