0172. Number Container

Input file name: contain.in
Output file name: contain.out
Time limit: 500 ms
Memory limit: 64 megabytes

Consider all MN N-digit numbers in the scale of notation with base M (leading zeros are allowed). Your task is to generate the lexicographically smallest string of digits of minimal possible length which will contain all these numbers as substrings if this string is infinitely appended to itself.

Input file

There are only two integers in input file: M and N. It is guaranteed that 2 ≤ M ≤ 10 and 1 ≤ N ≤ 10. It is always true that MN ≤ 1000000.

Output file

Output the lexcographically smallest string of minimal length which solves this task.

Examples:

contain.incontain.out
2 20011


Source: Petrozavodsk Summer 2003. KOTEHOK's Contest, Sunday, August 31
Author: Andrew Lopatin

Discuss       Submit a solution



Printable version