#F. B - Factorial Yen Coin

    传统题 1000ms 256MiB

B - Factorial Yen Coin

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

B - Factorial Yen Coin

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:

PP

Output

Print the minimum number of coins needed.


9
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.


119
10

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


10000000
24

2025寒假ATC码力训练营第九次练习

未参加
状态
已结束
规则
IOI
题目
6
开始于
2025-2-1 13:00
结束于
2025-2-1 14:30
持续时间
1.5 小时
主持人
参赛人数
5