The least common multiple
Easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
Given a number (X) and a set of digits (D).
Your task is to append the minimum number of digits from (D) to (X) so that the resulting number is divisible by (k). The resulting number should be the smallest possible.
Input
The first line of the input contains two natural numbers (X) and (k) ((1 X 10^1000), (2 k 100000)). The second line contains the number of digits in the set (D). The third line lists these digits separated by spaces.
Output
Output a single line containing the smallest number obtained from (X) by appending digits from (D) that is divisible by (k). If no such number can be formed, output (-1).
Examples
Input #1
Answer #1
Submissions 432
Acceptance rate 12%