luogu#P5228. [AHOI2013] 找硬币

[AHOI2013] 找硬币

Problem Description

Little Snake is the minister of the finance department. Recently, she decided to create a series of new currencies. Suppose the denominations she will create are x1,x2,x3x_1, x_2, x_3 \dots. Then x1x_1 must be 11, and xbx_b must be a positive integer multiple of xax_a (b>ab > a). For example, 1,5,125,2501, 5, 125, 250 is a valid coin sequence, while 1,5,100,1251, 5, 100, 125 is not.

Starting from some day, the lovely Snake fell in love with a cute thing—“rabbit dolls” (tu zi)! From then on, she took the one-way path of buying any rabbit doll she encountered. One day, she saw NN cute rabbit dolls. Suppose the prices of these NN rabbit dolls are a1,a2aNa_1, a_2 \dots a_N. Now she wants to know: under which valid coin sequence, the total number of coins needed to buy these NN rabbit dolls is the smallest. No change can be given when buying rabbit dolls.

Input Format

The first line contains an integer NN, representing the number of rabbit dolls.
The second line contains NN integers separated by spaces, representing the prices of the NN rabbit dolls.

Output Format

One line containing an integer, representing the minimum number of coins paid.

2
25 102
4

Hint

1N501 \leq N \leq 50.

1ai1051 \leq a_i \leq 10^5.

Translated by ChatGPT 5