码迷,mamicode.com
首页 > 其他好文 > 详细

Multiple(BFS+同余剪枝)

时间:2018-08-30 00:03:09      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:between   least   blog   each   seve   following   hat   同余   pst   

Description

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).

Input

The input 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.

Output

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. 

An example of input and output:

Sample Input

22
3
7
0
1

2
1
1

Sample Output

110
0



https://blog.csdn.net/u013480600/article/details/26458435

Multiple(BFS+同余剪枝)

标签:between   least   blog   each   seve   following   hat   同余   pst   

原文地址:https://www.cnblogs.com/wkfvawl/p/9557489.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!