#P9769. [HUSTFC 2023] 简单的加法乘法计算题

[HUSTFC 2023] 简单的加法乘法计算题

Problem Description

JokerShaco has a number xx. Initially, x=0x=0, and he wants to change xx into yy. To achieve this, he can use two sets AA and BB. Set AA contains nn elements, which are all positive integers from 11 to nn. Set BB contains mm elements. Each time, he can perform the following operations on xx any number of times:

  • Choose an element aa from AA, and add aa to xx.
  • Choose an element bb from BB, and multiply xx by bb.

Given yy, nn, mm, and the specific values of the mm elements in BB, JokerShaco wants to know the minimum number of operations needed to make xx become yy.

Input Format

The first line contains three integers y (1y5106)y\ (1\le y\le 5\cdot 10^6), n (1n5106)n\ (1\le n\le 5\cdot 10^6), and m (1m10)m\ (1\le m\le 10), with meanings as described above.

The second line contains mm positive integers. The ii-th one represents the ii-th element in BB, bi (1bi5106)b_i\ (1\le b_i\le 5\cdot 10^6).

Output Format

Output one integer, representing the minimum number of operations needed to make xx become yy. Under the conditions of the problem, it is guaranteed that xx can always be changed into yy.

10 3 1
2

3

100 6 3
2 3 5

3

Hint

Translated by ChatGPT 5