問題一覧 > 通常問題

No.3204 Permuted Integer

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 116
作問者 : amesyu / テスター : noshinn lmorinn 👑 qand
お気に入りにしたユーザー ProblemId : 12319 / 自分の提出
問題文最終更新日: 2025-07-17 14:34:44
Permuted Integer
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. Show the original
yukicoder contest 474 (順位表) の他の問題:

Problem Statement

You are given a positive integer $N$. Determine whether any of the integers obtained by rearranging the digits of the decimal representation of $N$ is a perfect square.
If such integers exist, output the smallest such perfect square; otherwise, output -1.
The result of the rearrangement may have unnecessary leading $0$s (leading zeros), but the output must not contain unnecessary $0$s.

Constraints

  • $1 \leq T \leq 10^5$
  • $1 \leq N \leq 10^9$
  • All input values are integers.

Input

$T$
$N_1$
$N_2$
$\vdots$
$N_T$

Output

Output $T$ lines. On the $i \ (1 \leq i \leq T)$-th line, output the answer for the $i$-th test case.

Sample

Sample 1
Input
6
18
2025
2024
8886519
62506357
4000
Output
81
225
-1
9865881
6375625
4

For the $1$st test case, 18 becomes a perfect square when rearranged into 81.
For the $2$nd test case, the rearrangements of 2025 that are perfect squares are 0225 and 2025. The minimum is 0225 = 225, so output 225.
For the $3$rd test case, no rearrangement of 2024 is a perfect square, so output -1.

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