A14551 | Scenes From a Memory
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
During the hypnosis session, Nicholas suddenly remembered a positive integer $n$ , which doesn't contain zeros in decimal notation.
Soon, when he returned home, he got curious: what is the maximum number of digits that can be removed from the number so that the number becomes not prime, that is, either composite or equal to one?
For some numbers doing so is impossible: for example, for number $53$ it's impossible to delete some of its digits to obtain a not prime integer. However, for all $n$ in the test cases of this problem, it's guaranteed that it's possible to delete some of their digits to obtain a not prime number.
Note that you cannot remove all the digits from the number.
A prime number is a number that has no divisors except one and itself. A composite is a number that has more than two divisors. $1$ is neither a prime nor a composite number.
Soon, when he returned home, he got curious: what is the maximum number of digits that can be removed from the number so that the number becomes not prime, that is, either composite or equal to one?
For some numbers doing so is impossible: for example, for number $53$ it's impossible to delete some of its digits to obtain a not prime integer. However, for all $n$ in the test cases of this problem, it's guaranteed that it's possible to delete some of their digits to obtain a not prime number.
Note that you cannot remove all the digits from the number.
A prime number is a number that has no divisors except one and itself. A composite is a number that has more than two divisors. $1$ is neither a prime nor a composite number.
输入格式
Each test contains multiple test cases.
The first line contains one positive integer $t$ ( $1 \le t \le 10^3$ ), denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains one positive integer $k$ ( $1 \le k \le 50$ ) — the number of digits in the number.
The second line of each test case contains a positive integer $n$ , which doesn't contain zeros in decimal notation ( $10^{k-1} \le n < 10^{k}$ ). It is guaranteed that it is always possible to remove less than $k$ digits to make the number not prime.
It is guaranteed that the sum of $k$ over all test cases does not exceed $10^4$ .
The first line contains one positive integer $t$ ( $1 \le t \le 10^3$ ), denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains one positive integer $k$ ( $1 \le k \le 50$ ) — the number of digits in the number.
The second line of each test case contains a positive integer $n$ , which doesn't contain zeros in decimal notation ( $10^{k-1} \le n < 10^{k}$ ). It is guaranteed that it is always possible to remove less than $k$ digits to make the number not prime.
It is guaranteed that the sum of $k$ over all test cases does not exceed $10^4$ .
输出格式
For every test case, print two numbers in two lines. In the first line print the number of digits, that you have left in the number. In the second line print the digits left after all delitions.
If there are multiple solutions, print any.
If there are multiple solutions, print any.
输入输出样例
输入 #1
7 3 237 5 44444 3 221 2 35 3 773 1 4 30 626221626221626221626221626221
输出 #1
2 27 1 4 1 1 2 35 2 77 1 4 1 6
In the first test case, you can't delete $2$ digits from the number $237$ , as all the numbers $2$ , $3$ , and $7$ are prime. However, you can delete $1$ digit, obtaining a number $27 = 3^3$ .
In the second test case, you can delete all digits except one, as $4 = 2^2$ is a composite number.
In the second test case, you can delete all digits except one, as $4 = 2^2$ is a composite number.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted