codeforces-scrape

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

1482B.md (2054B)


      1 Source: https://codeforces.com/problemset/problem/1482/B
      2 
      3 B. Restore Modulo
      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 For the first place at the competition, Alex won many arrays of integers and was assured that these arrays are very expensive. After the award ceremony Alex decided to sell them. There is a rule in arrays pawnshop: you can sell array only if it can be compressed to a generator.
     22 
     23 This generator takes four non-negative numbers $n$, $m$, $c$, $s$. $n$ and $m$ must be positive, $s$ non-negative and for $c$ it must be true that $0 \leq c \lt m$. The array $a$ of length $n$ is created according to the following rules:
     24 
     25 * $a_1 = s \bmod m$, here $x \bmod y$ denotes remainder of the division of $x$ by $y$;
     26 * $a_i = (a_{i-1} + c) \bmod m$ for all $i$ such that $1 \lt i \le n$.
     27 
     28 For example, if $n = 5$, $m = 7$, $c = 4$, and $s = 10$, then $a = [3, 0, 4, 1, 5]$.
     29 
     30 Price of such an array is the value of $m$ in this generator.
     31 
     32 Alex has a question: how much money he can get for each of the arrays. Please, help him to understand for every array whether there exist four numbers $n$, $m$, $c$, $s$ that generate this array. If yes, then maximize $m$.
     33 
     34 Input
     35 
     36 The first line contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of arrays.
     37 
     38 The first line of array description contains a single integer $n$ ($1 \leq n \leq 10^5$) — the size of this array.
     39 
     40 The second line of array description contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 10^9$ ) — elements of the array.
     41 
     42 It is guaranteed that the sum of array sizes does not exceed $10^5$.
     43 
     44 Output
     45 
     46 For every array print:
     47 
     48 * $-1$, if there are no such four numbers that generate this array;
     49 * $0$, if $m$ can be arbitrary large;
     50 * the maximum value $m$ and any appropriate $c$ ($0 \leq c \lt m$) in other cases.
     51 
     52 Example
     53 
     54 Input
     55 
     56 ```
     57 6
     58 6
     59 1 9 17 6 14 3
     60 3
     61 4 2 2
     62 3
     63 7 3 4
     64 3
     65 2 2 4
     66 5
     67 0 1000000000 0 1000000000 0
     68 2
     69 1 1
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 19 8
     76 -1
     77 -1
     78 -1
     79 2000000000 1000000000
     80 0
     81 ```