Write a backtracking program to print all the -digit numbers such that none of its prefixes (the whole number included) is a multiple of any of given forbidden divisors .
For instance, if , and the forbidden divisors are 2, 3, 5, 7, 11 and 19, then 137 is allowed, because none of its three prefixes 1, 13 and 137 is a multiple of any . By contrast, 433 is not allowed, because some of its three prefixes 4, 43 and 433 is multiple os some (4 is multiple of 2).
Input consists of several cases. Each case begins with and , followed by different integer numbers between 2 and 1000. You can assume and .
For every case, print all the numbers with exactly digits and no forbidden prefixes, one per line and in increasing order. Print a line with 10 dashes at the end of each case.
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T11:59:38.372Z
© Jutge.org, 2006–2026.
https://jutge.org