Very Strange String
Time limit2sMemory limit1024 MB
Given k and m, the task is to build a lowercase string of length at most m whose strangeness (the sum of G_i times F_i) equals k.
- Level
Hard9 of 10
- Topics
- String matching, Math, Implementation
- Solved
- No attempts yet
Statement
Professor X likes to solve puzzles in the morning. But one puzzle was too hard even for the sick professor.
The professor likes to define unusual functions, especially for strings. Examples of such functions are and .
A substring is a string obtained from the original by deleting some (possibly zero) characters from the beginning and the end. The -th prefix is the string that keeps exactly characters from the start, with nothing removed from the end. The -th suffix is the string with nothing removed from the end and exactly characters removed from the start.
For a string , is the length of the longest suffix of the -th prefix that is a prefix of and is not equal to the -th prefix itself. is the length of the longest prefix of the -th suffix that is a prefix of . The professor decided that and , and it is hard to argue with him.
The strangeness of a string is the sum of the products of and over all from 1 to . Find a string of length at most whose strangeness is equal to the given number .
When Wolverine was met, the professor asked a comrade for help. But even for the hero, this puzzle was too hard. Can you solve it?
Input
The first line contains the integers and (). The value of is fixed within each test group; see the Scoring section.
Output
Print a string of lowercase Latin letters of length at most whose strangeness is . If several strings fit, print any of them. The answer is guaranteed to exist.
Hint
Consider the string aaaa. Its is and its is . So the strangeness of the string is .