每日一题 第三十九期 Codeforces Round 931 (Div. 2)

B. Yet Another Coin Problem

time limit per test: 1 second

memory limit per test: 256 megabytes

input: standard input

output: standard output

You have 5 5 5 different types of coins, each with a value equal to one of the first 5 5 5 triangular numbers: 1 1 1, 3 3 3, 6 6 6, 10 10 10, and 15 15 15. 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 n n n.

We can show that the answer always exists.

Input

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

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

Output

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

Example
inputCopy
14
1
2
3
5
7
11
12
14
16
17
18
20
98
402931328
outputCopy
1
2
1
3
2
2
2
3
2
3
2
2
8
26862090

Note

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

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

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

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

#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<numeric>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=998244353;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;

int t;
int n;
int main()
{
	cin >> t;
	while(t --){
		int n;
		cin >> n;
		int mins = 1e9;
		for(int i = 0; i <= 2; i ++)
		{
			for(int j = 0; j <= 1; j ++)
			{
				for(int k = 0; k <= 4; k ++)
				{
					for(int l = 0; l <= 2; l ++)
					{
				        int sum = n - (i * 1 + j * 3 + k * 6 + l * 10);
						if(sum < 0 || sum % 15 != 0) continue;
						mins = min(mins, i + j + k + l + sum / 15);
					}
				}
			}
			
		}
		cout << mins << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值