atcoder#CODEFESTIVAL2016EXB. Exact Payment
Exact Payment
Score : points
Problem Statement
The currency used in Takahashi Kingdom is Myon. There are -, -, -, - and -Myon coins, and so forth. Formally, there are -Myon coins for any non-negative integer .
There are items being sold at Ex Store. The price of the -th item is Myon.
Takahashi is going to buy some, at least one, possibly all, of these items. He hates receiving change, so he wants to bring coins to the store so that he can pay the total price without receiving change, no matter what items he chooses to buy. Also, since coins are heavy, he wants to bring as few coins as possible.
Find the minimum number of coins he must bring to the store. It can be assumed that he has an infinite supply of coins.
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print the minimum number of coins Takahashi must bring to the store, so that he can pay the total price without receiving change, no matter what items he chooses to buy.
3
43 24 37
16
There are seven possible total prices: and . With seven -Myon coins, eight -Myon coins and one -Myon coin, Takahashi can pay any of these without receiving change.
5
49735011221 970534221705 411566391637 760836201000 563515091165
105