102081: [AtCoder]ABC208 B - Factorial Yen Coin

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $200$ points

Problem Statement

The coins used in the Kingdom of Takahashi are $1!$-yen coins, $2!$-yen coins, $\dots$, and $10!$-yen coins. Here, $N! = 1 \times 2 \times \dots \times N$.

Takahashi has $100$ of every kind of coin, and he is going to buy a product worth $P$ yen by giving the exact amount without receiving change.

We can prove that there is always such a way to make payment.

At least how many coins does he need to use in his payment?

Constraints

  • $1 \leq P \leq 10^7$
  • $P$ is an integer.

Input

Input is given from Standard Input in the following format:

$P$

Output

Print the minimum number of coins needed.


Sample Input 1

9

Sample Output 1

3

By giving one $(1! =) 1$-yen coin, one $(2! =) 2$-yen coin, and one $(3! =) 6$-yen coin, we can make the exact payment for the product worth $9$ yen. There is no way to pay this amount using fewer coins.


Sample Input 2

119

Sample Output 2

10

We should use one $1!$-yen coin, two $2!$-yen coins, three $3!$-yen coins, and four $4!$-yen coins.


Sample Input 3

10000000

Sample Output 3

24

Input

题意翻译

有若干个数,它们中的每个数都是 $1!,2!,...,10!$ 中的一个。输入这些数的和,输出这些数最少有多少个。

加入题单

上一题 下一题 算法标签: