Problem F
Anagram and Multiplication
Input:
Standard
Input
Output: Standard Output
There are some amazing M-digit, N-based numbers which when multiplied by 2, 3, …M, results in new numbers which are just anagrams of the original number. For example 142857 is such a 6-digit decimal (10-based) number as shown below:
2 x 142,857 = 285,7143 x 142,857 = 428,5714 x 142,857 = 571,4285 x 142,857 = 714,2856 x 142,857 = 857,142
Given the value of M and N your job is to find such a number. Without any proof I can assure you that for a single pair of value of M and N there is at most one such number.
Each line contains two integers
M(3≤M≤6) and N(4≤N≤400). The meaning of M and N is
given in the problem statement.
Input is terminated by a line where M=N=0. This case should not be processed.
For each line of input you should produce one line of output. This line should contain M integers separated by a single space. All these integers are within 0 and N-1 (inclusive). These integers are the values of digits of the required N-based amazing number. The digits should be printed in descending order of significance (The left most integer is the value of the most significant digit and the rightmost integer is the value of the least significant digit of the desired number). If there is no such N based M-digit number print the string “Not found.” (without the quotes) instead. Look at the output for sample input for details.
6 106 1000 0 |
1 4 2 8 5 7Not found.
|
Problem setter: Shahriar Manzoor
Special Thanks: Derek Kisman