310619: CF1861A. Prime Deletion

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

Description

A. Prime Deletiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

A prime number is a positive integer that has exactly two different positive divisors: $1$ and the integer itself. For example, $2$, $3$, $13$ and $101$ are prime numbers; $1$, $4$, $6$ and $42$ are not.

You are given a sequence of digits from $1$ to $9$, in which every digit from $1$ to $9$ appears exactly once.

You are allowed to do the following operation several (maybe zero) times: choose any digit from the sequence and delete it. However, you cannot perform this operation if the sequence consists of only two digits.

Your goal is to obtain a sequence which represents a prime number. Note that you cannot reorder the digits in the sequence.

Print the resulting sequence, or report that it is impossible to perform the operations so that the resulting sequence is a prime number.

Input

The first line contains one integer $t$ ($1 \le t \le 5000$) — the number of test cases.

Each test case consists of one line containing a string of $9$ digits (without any characters between them). Each digit from $1$ to $9$ appears in this string exactly once.

Output

For each test case, print the answer on a separate line as follows:

  • if it is impossible to perform the described operations, print $-1$;
  • otherwise, print any sequence that represents a prime number, which can be obtained from the given string performing several (maybe zero) operations described in the statement. If there are multiple such sequences, you can print any one of them.
ExampleInput
4
123456789
987654321
243567918
576318429
Output
167
53
3571
57638429

Output

题目大意:
题目名为 "素数删除"。素数是一个正整数,它恰好有两个不同的正除数:1 和它本身。例如,2、3、13 和 101 是素数;而 1、4、6 和 42 不是素数。

给定一个由 1 到 9 的数字组成的序列,每个数字 1 到 9 在序列中恰好出现一次。

你可以进行以下操作若干次(可能为零次):从序列中选择任意一个数字并删除它。但是,如果序列只包含两个数字,你不能执行此操作。

你的目标是获得一个表示素数的序列。注意,你不能重新排序序列中的数字。

打印结果序列,或者报告无法执行操作使得结果序列是一个素数。

输入输出数据格式:
输入:
- 第一行包含一个整数 t(1 ≤ t ≤ 5000)——测试用例的数量。
- 每个测试用例由一行组成,该行包含一个由 9 个数字组成的字符串(数字之间没有其他字符)。字符串中每个数字 1 到 9 出现恰好一次。

输出:
- 对于每个测试用例,按照以下格式在单独的一行中打印答案:
- 如果无法执行描述的操作,打印 -1;
- 否则,打印任何可以由给定的字符串通过执行题目描述的操作得到的表示素数的序列。如果有多个这样的序列,你可以打印其中任何一个。

示例:
输入:
```
4
123456789
987654321
243567918
576318429
```
输出:
```
167
53
3571
57638429
```

请注意,素数的判断和生成逻辑需要根据编程题目的具体要求实现,这里只提供了题目描述和示例输入输出。题目大意: 题目名为 "素数删除"。素数是一个正整数,它恰好有两个不同的正除数:1 和它本身。例如,2、3、13 和 101 是素数;而 1、4、6 和 42 不是素数。 给定一个由 1 到 9 的数字组成的序列,每个数字 1 到 9 在序列中恰好出现一次。 你可以进行以下操作若干次(可能为零次):从序列中选择任意一个数字并删除它。但是,如果序列只包含两个数字,你不能执行此操作。 你的目标是获得一个表示素数的序列。注意,你不能重新排序序列中的数字。 打印结果序列,或者报告无法执行操作使得结果序列是一个素数。 输入输出数据格式: 输入: - 第一行包含一个整数 t(1 ≤ t ≤ 5000)——测试用例的数量。 - 每个测试用例由一行组成,该行包含一个由 9 个数字组成的字符串(数字之间没有其他字符)。字符串中每个数字 1 到 9 出现恰好一次。 输出: - 对于每个测试用例,按照以下格式在单独的一行中打印答案: - 如果无法执行描述的操作,打印 -1; - 否则,打印任何可以由给定的字符串通过执行题目描述的操作得到的表示素数的序列。如果有多个这样的序列,你可以打印其中任何一个。 示例: 输入: ``` 4 123456789 987654321 243567918 576318429 ``` 输出: ``` 167 53 3571 57638429 ``` 请注意,素数的判断和生成逻辑需要根据编程题目的具体要求实现,这里只提供了题目描述和示例输入输出。

加入题单

上一题 下一题 算法标签: