codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1562B.md (2412B)


      1 Source: https://codeforces.com/problemset/problem/1562/B
      2 
      3 B. Scenes From a Memory
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 During the hypnosis session, Nicholas suddenly remembered a positive integer $n$, which doesn't contain zeros in decimal notation.
     22 
     23 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?
     24 
     25 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.
     26 
     27 Note that you cannot remove all the digits from the number.
     28 
     29 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.
     30 
     31 Input
     32 
     33 Each test contains multiple test cases.
     34 
     35 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.
     36 
     37 The first line of each test case contains one positive integer $k$ ($1 \le k \le 50$) — the number of digits in the number.
     38 
     39 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 \lt 10^{k}$). It is guaranteed that it is always possible to remove less than $k$ digits to make the number not prime.
     40 
     41 It is guaranteed that the sum of $k$ over all test cases does not exceed $10^4$.
     42 
     43 Output
     44 
     45 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.
     46 
     47 If there are multiple solutions, print any.
     48 
     49 Example
     50 
     51 Input
     52 
     53 ```
     54 7
     55 3
     56 237
     57 5
     58 44444
     59 3
     60 221
     61 2
     62 35
     63 3
     64 773
     65 1
     66 4
     67 30
     68 626221626221626221626221626221
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 2
     75 27
     76 1
     77 4
     78 1
     79 1
     80 2
     81 35
     82 2
     83 77
     84 1
     85 4
     86 1
     87 6
     88 ```
     89 
     90 Note
     91 
     92 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$.
     93 
     94 In the second test case, you can delete all digits except one, as $4 = 2^2$ is a composite number.