codeforces-scrape

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

660A.md (1415B)


      1 Source: https://codeforces.com/problemset/problem/660/A
      2 
      3 A. Co-prime Array
      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 You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
     22 
     23 In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
     24 
     25 An array is co-prime if any two adjacent numbers of it are co-prime.
     26 
     27 In the number theory, two integers *a* and *b* are said to be co-prime if the only positive integer that divides both of them is 1.
     28 
     29 Input
     30 
     31 The first line contains integer *n* (1 ≤ *n* ≤ 1000) — the number of elements in the given array.
     32 
     33 The second line contains *n* integers *a**i* (1 ≤ *a**i* ≤ 109) — the elements of the array *a*.
     34 
     35 Output
     36 
     37 Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
     38 
     39 The second line should contain *n* + *k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array *a* by adding *k* elements to it.
     40 
     41 If there are multiple answers you can print any one of them.
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 3  
     49 2 7 28
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 1  
     56 2 7 9 28
     57 ```