201232: [AtCoder]ARC123 C - 1, 2, 3 - Decomposition

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

Description

Score : $600$ points

Problem Statement

Given is a positive integer $N$. Consider a sequence of integers $A = (A_1, \ldots, A_K)$ that satisfies the conditions below:

  • $\sum_{i=1}^K A_i = N$;
  • each $A_i$ is a positive integer such that every digit in its decimal notation is $1$, $2$, or $3$.

Find the minimum possible value of $K$, that is, the number of elements in such a sequence $A$.

Process $T$ test cases per input file.

Constraints

  • $1\leq T\leq 1000$
  • $1\leq N\leq 10^{18}$

Input

Input is given from Standard Input in the following format:

$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$

Each case is in the following format:

$N$

Output

Print the answers.


Sample Input 1

5
456
10000
123
314
91

Sample Output 1

2
4
1
2
4

For each $N$, one optimal $A$ is shown below.

  • For $N = 456$: $A = (133, 323)$.
  • For $N = 10000$: $A = (323, 3132, 3232, 3313)$.
  • For $N = 123$: $A = (123)$.
  • For $N = 314$: $A = (312,2)$.
  • For $N = 91$: $A = (22,23,23,23)$.

Input

题意翻译

### 题目描述 给出一个正整数 $n$ ,求 $n$ 至少可以表示为多少个 「十进制下仅含有 $1,2,3$ 的正整数」 的和? 翻译 by [_FJqwq](https://www.luogu.com.cn/user/755947) ### 输入格式 单测试点包含多组数据,共 $T+1$ 行。 第 $1$ 行,包括一个正整数 $T$,表示 $T$ 组询问。 接下来 $T$ 行,每行包括一个正整数 $n$,表示询问。 ### 输出格式 共 $T$ 行,每行一个正整数,表示对应询问的答案。 ### 样例解释 #### 样例#1 ``` 456 = 133 + 323 10000 = 323 + 3132 + 3232 + 3313 123 = 123 314 = 312 + 2 91 = 22 + 23 + 23 + 23 ```

加入题单

算法标签: