codeforces-scrape

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

1618C.md (1311B)


      1 Source: https://codeforces.com/problemset/problem/1618/C
      2 
      3 C. Paint the Array
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 $a$ consisting of $n$ positive integers. You have to choose a positive integer $d$ and paint all elements into two colors. All elements which are divisible by $d$ will be painted red, and all other elements will be painted blue.
     22 
     23 The coloring is called beautiful if there are no pairs of adjacent elements with the same color in the array. Your task is to find any value of $d$ which yields a beautiful coloring, or report that it is impossible.
     24 
     25 Input
     26 
     27 The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
     28 
     29 The first line of each testcase contains one integer $n$ ($2 \le n \le 100$) — the number of elements of the array.
     30 
     31 The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{18}$).
     32 
     33 Output
     34 
     35 For each testcase print a single integer. If there is no such value of $d$ that yields a beautiful coloring, print $0$. Otherwise, print any suitable value of $d$ ($1 \le d \le 10^{18}$).
     36 
     37 Example
     38 
     39 Input
     40 
     41 ```
     42 5
     43 5
     44 1 2 3 4 5
     45 3
     46 10 5 15
     47 3
     48 100 10 200
     49 10
     50 9 8 2 6 6 2 8 6 5 4
     51 2
     52 1 3
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 2
     59 0
     60 100
     61 0
     62 3
     63 ```