HDU - 4474
Description
There are tons of problems about integer multiples. Despite the fact that the topic is not original, the content is highly challenging. That’s why we call it “Yet Another Multiple Problem”.
In this problem, you’re asked to solve the following question: Given a positive integer n and m decimal digits, what is the minimal positive multiple of n whose decimal notation does not contain any of the given digits? Input
There are several test cases.
For each test case, there are two lines. The first line contains two integers n and m (1 ≤ n ≤ 10 4). The second line contains m decimal digits separated by spaces. Input is terminated by EOF. Output
For each test case, output one line “Case X: Y” where X is the test case number (starting from 1) while Y is the minimal multiple satisfying the above-mentioned conditions or “-1” (without quotation marks) in case there does not exist such a multiple.
Sample Input
Sample Output
Hint Source
2012 Asia Chengdu Regional Contest
题意:
给出一个数字n,和m个一位数字,求n的最小倍数,使得其中不会出现这m个数字。
思路:
开始想的是暴力枚举一下= = 结果发现根本找不到一个上界,果断弃疗。
其实一个BFS,再加一个优化就可以解决。
同余剪枝:对于每次搜索到的数x, 判断一下 x mod n 是否已经存在。如果存在的话,说明有比当前结果更优的解,直接跳过。直到x mod n == 0,回溯输出ans。
AC代码:
|