CF1562B.Scenes From a Memory

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

During the hypnosis session, Nicholas suddenly remembered a positive integer nn, 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 5353 it's impossible to delete some of its digits to obtain a not prime integer. However, for all nn 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. 11 is neither a prime nor a composite number.

在催眠过程中,尼古拉斯突然想起一个正整数 nn,其十进制表示中不包含数字 00。

不久后,当他回到家时,他产生了好奇:最多可以删除该数中的多少位数字,使得剩余的数变为非质数(即:为合数,或等于 11)?

对某些数而言,这是不可能实现的:例如,对数字 5353,无论删除其哪些数字,都无法得到一个非质数。然而,本题所有测试用例中的 nn 均保证一定存在某种删除方式,使得剩余数字构成一个非质数。

注意:你不能删除该数的所有数字。

质数是指除 11 和它自身外没有其他正因数的数;合数是指具有超过两个正因数的数;而 11 既不是质数,也不是合数。

输入格式

Each test contains multiple test cases.

The first line contains one positive integer tt (1≤t≤1031 \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 kk (1≤k≤501 \le k \le 50) — the number of digits in the number.

The second line of each test case contains a positive integer nn, which doesn't contain zeros in decimal notation (10k−1≤n<10k10^{k-1} \le n \lt 10^{k}). It is guaranteed that it is always possible to remove less than kk digits to make the number not prime.

It is guaranteed that the sum of kk over all test cases does not exceed 10410^4.

每个测试包含多个测试用例。

第一行包含一个正整数 tt(1≤t≤1031 \le t \le 10^3),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个正整数 kk(1≤k≤501 \le k \le 50)—— 表示该数的位数。

每个测试用例的第二行包含一个正整数 nn,其十进制表示中不含数字 00(满足 10k−1≤n<10k10^{k-1} \le n \lt 10^{k})。保证总能通过删除少于 kk 个数字,使得该数变为合数。

保证所有测试用例的 kk 值之和不超过 10410^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.

对于每个测试用例,在两行中输出两个数字。第一行输出删除后剩余的数字位数;第二行输出删除后剩余的数字。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#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 22 digits from the number 237237, as all the numbers 22, 33, and 77 are prime. However, you can delete 11 digit, obtaining a number 27=3327 = 3^3.

In the second test case, you can delete all digits except one, as 4=224 = 2^2 is a composite number.

在第一个测试用例中,你无法从数字 237237 中删除 22 位数字,因为 22、33 和 77 均为质数。然而,你可以删除 11 位数字,得到数字 27=3327 = 3^3。

在第二个测试用例中,你可以删除除一位以外的所有数字,因为 4=224 = 2^2 是一个合数。

输入解题思路,AI测评打分。不知道怎么写?

首页