#P1562B. Scenes From a Memory

    ID: 1148 远端评测题 1000ms 256MiB 尝试: 7 已通过: 2 难度: 10 上传者: 标签>brute forceconstructive algorithmsimplementationmathnumber theory*1000

Scenes From a Memory

Scenes From a Memory

题面翻译

题目描述

给出一个正整数 nnnn 中不包含 00。求最大删去多少位使其变成一个合数或 11。数据保证一定存在答案。

素数是指除 11 和它本身外没有除数的数。合数是指一个有两个以上除数的数。11 既不是质数也不是合数。

输入格式

第一行一个正整数 t(1t103)t(1\leq t \leq 10^3),表示数据组数。

每组数据第一行一个正整数 k(1k50)k(1\leq k\leq 50),表示数字的位数。

第二行一整正整数 n(10k1n10k)n(10^{k-1}\leq n \leq 10^{k})

输出格式

对于每组数据,第一行输出剩下的数的位数,第二行输出剩下的数。

若有多组解,输出任意一个即可。

题目描述

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

输入格式

Each test contains multiple test cases.

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

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

It is guaranteed that the sum of k k over all test cases does not exceed 104 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.

样例 #1

样例输入 #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 2 digits from the number 237 237 , as all the numbers 2 2 , 3 3 , and 7 7 are prime. However, you can delete 1 1 digit, obtaining a number 27=33 27 = 3^3 .

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