CF1934B.Yet Another Coin Problem

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have 55 different types of coins, each with a value equal to one of the first 55 triangular numbers: 11, 33, 66, 1010, and 1515. These coin types are available in abundance. Your goal is to find the minimum number of these coins required such that their total value sums up to exactly nn.

We can show that the answer always exists.

你有 55 种不同类型的硬币,其面值分别为前 55 个三角形数:11、33、66、1010 和 1515。这些类型的硬币数量充足。你的目标是找出所需硬币的最少数量,使得它们的总面值恰好等于 nn。

可以证明,该问题的答案总是存在。

输入格式

The first line contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤1091 \leq n \leq 10^9) — the target value.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1091 \leq n \leq 10^9)—— 目标值。

输出格式

For each test case, output a single number — the minimum number of coins required.

对于每个测试用例,输出一个数字——所需的最少硬币数量。

输入输出样例

  • 输入#1

    14
    1
    2
    3
    5
    7
    11
    12
    14
    16
    17
    18
    20
    98
    402931328

    输出#1

    1
    2
    1
    3
    2
    2
    2
    3
    2
    3
    2
    2
    8
    26862090

说明/提示

In the first test case, for n=1n = 1, the answer is 11 since only one 11 value coin is sufficient. 1=1⋅11 = 1 \cdot 1.

In the fourth test case, for n=5n = 5, the answer is 33, which can be achieved using two 11 value coins and one 33 value coin. 5=2⋅1+1⋅35 = 2 \cdot 1 + 1 \cdot 3.

In the seventh test case, for n=12n = 12, the answer is 22, which can be achieved using two 66 value coins.

In the ninth test case, for n=16n = 16, the answer is 22, which can be achieved using one 11 value coin and one 1515 value coin or using one 1010 value coin and one 66 value coin. 16=1⋅1+1⋅15=1⋅6+1⋅1016 = 1 \cdot 1 + 1 \cdot 15 = 1 \cdot 6 + 1 \cdot 10.

在第一个测试用例中,当 n=1n = 1 时,答案为 11,因为仅需一枚面值为 11 的硬币即可。1=1⋅11 = 1 \cdot 1。

在第四个测试用例中,当 n=5n = 5 时,答案为 33,可通过使用两枚面值为 11 的硬币和一枚面值为 33 的硬币实现。5=2⋅1+1⋅35 = 2 \cdot 1 + 1 \cdot 3。

在第七个测试用例中,当 n=12n = 12 时,答案为 22,可通过使用两枚面值为 66 的硬币实现。

在第九个测试用例中,当 n=16n = 16 时,答案为 22,可通过使用一枚面值为 11 的硬币和一枚面值为 1515 的硬币实现,也可通过使用一枚面值为 1010 的硬币和一枚面值为 66 的硬币实现。16=1⋅1+1⋅15=1⋅6+1⋅1016 = 1 \cdot 1 + 1 \cdot 15 = 1 \cdot 6 + 1 \cdot 10。

输入解题思路,AI测评打分。不知道怎么写?

首页