1657Multiple

1657   Multiple

题目描述

a program that, given a natural number N between 0 and 4999 (inclusively), and M distinct decimal digits X1,X2..XM (at least one), finds the smallest strictly positive multiple of N that has no other digits besides X1,X2..XM (if such a multiple exists).

输入格式:

The input file has several data sets separated by an empty line, each data set having the following format:

On the first line - the number N
On the second line - the number M
On the following M lines - the digits X1,X2..XM.

输出格式:

For each data set, the program should write to standard output on a single line the multiple, if such a multiple exists, and 0 otherwise.

输入样例 复制
22
3
7
0
1

2
1
1
输出样例 复制
110
0

说明

2
4
通过提交
时空限制10000ms/32mb
题目来源
评测方式在线评测
题目类型
难        度