問題一覧 > 通常問題

No.362 Kadomatsu Number

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 256 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 48
作問者 : koyumeishi / テスター : 🐬hec
お気に入りにしたユーザー ProblemId : 1010 / 自分の提出
問題文最終更新日: 2026-06-26 00:39:08
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder 門松コンテスト (順位表) の他の問題:

Problem Statement

A Kadomatsu sequence is a sequence $A_1, A_2, A_3$ of $3$ elements that satisfies the following 2 conditions.

  • $A_1, A_2, A_3$ are all distinct
  • Among the $3$ elements, $A_2$ is the largest or $A_2$ is the smallest

Let $X_i$ be the $i$-th digit from the top of an $N$-digit ($3 \leq N$) positive integer $X$.
If the sequences $X_i$, $X_{i+1}$, $X_{i+2}$ ($1 \leq i \leq N-2$ ) are all Kadomatsu sequences, $X$ is a Kadomatsu number.
For example, 4514 and 893 are Kadomatsu numbers, but 114514 and 89 are not Kadomatsu numbers.

When $X$ is a Kadomatsu number and there exist $K$ Kadomatsu numbers smaller than $X$, $X$ is said to be the $K+1$-th Kadomatsu number.
The 1st Kadomatsu number is 102, the 404th Kadomatsu number is 893, and the 1000th Kadomatsu number is 3296.

Given a positive integer $K$ ($1 \leq K \leq 10^{10}$), find the $K$-th Kadomatsu number.

Input

The first line contains the number of test cases $T$. ($1 \leq T \leq 10$)
$T$
Each of the following $T$ lines contains $K$ ($1 \leq K \leq 10^{10}$) for each test case.
$K$

All inputs are integers.

Output

For each test case, output the $K$-th Kadomatsu number on one line.

Sample

Sample 1
Input
5
1
2
3
4
5
Output
102
103
104
105
106

Note that there are no 1-digit or 2-digit Kadomatsu numbers.

Sample 2
Input
4
114
215
404
1000
Output
328
514
893
3296

Sample 3
Input
1
10000000000
Output
37294859064823

This is the largest case. 10^10 does not fit in a 32-bit integer type. Be careful about overflow not only during calculation but also during input and output.
Incidentally, this case is placed near the end of the tests, so you will not get knocked out by TLE on this case.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。