CF1484B.Restore Modulo

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

This generator takes four non-negative numbers nn, mm, cc, ss. nn and mm must be positive, ss non-negative and for cc it must be true that 0≤c<m0 \leq c \lt m. The array aa of length nn is created according to the following rules:

  • a1=s mod ma_1 = s \bmod m, here x mod yx \bmod y denotes remainder of the division of xx by yy;
  • ai=(ai−1+c) mod ma_i = (a_{i-1} + c) \bmod m for all ii such that 1<i≤n1 \lt i \le n.

For example, if n=5n = 5, m=7m = 7, c=4c = 4, and s=10s = 10, then a=[3,0,4,1,5]a = [3, 0, 4, 1, 5].

Price of such an array is the value of mm in this generator.

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 nn, mm, cc, ss that generate this array. If yes, then maximize mm.

在比赛第一名的奖品中,亚历克斯赢得了许多整数数组,并被告知这些数组非常昂贵。颁奖仪式结束后,亚历克斯决定出售它们。数组当铺有一条规则:只有当一个数组可以被压缩为某个生成器时,才能出售该数组。

该生成器接收四个非负整数 nn、mm、cc、ss,其中 nn 和 mm 必须为正整数,ss 为非负整数,且 cc 需满足 0≤c<m0 \leq c < m。按如下规则构造长度为 nn 的数组 aa:

  • a1=s mod ma_1 = s \bmod m,此处 x mod yx \bmod y 表示 xx 除以 yy 所得的余数;
  • 对所有满足 1<i≤n1 < i \le n 的 ii,有 ai=(ai−1+c) mod ma_i = (a_{i-1} + c) \bmod m。

例如,若 n=5n = 5、m=7m = 7、c=4c = 4、s=10s = 10,则 a=[3,0,4,1,5]a = [3, 0, 4, 1, 5]。

此类数组的价格即为其生成器中参数 mm 的值。

亚历克斯有一个问题:对于他拥有的每个数组,他最多能获得多少钱?请帮助他判断:对每一个给定数组,是否存在四元组 nn、mm、cc、ss 能够生成该数组;若存在,则求出最大的可能的 mm 值。

输入格式

The first line contains a single integer tt (1≤t≤1051 \leq t \leq 10^5) — the number of arrays.

The first line of array description contains a single integer nn (1≤n≤1051 \leq n \leq 10^5) — the size of this array.

The second line of array description contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \leq a_i \leq 10^9 ) — elements of the array.

It is guaranteed that the sum of array sizes does not exceed 10510^5.

第一行包含一个整数 tt(1≤t≤1051 \leq t \leq 10^5)—— 数组的个数。

每个数组描述的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 该数组的大小。

每个数组描述的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \leq a_i \leq 10^9)—— 数组的元素。

保证所有数组的大小之和不超过 10510^5。

输出格式

For every array print:

  • −1-1, if there are no such four numbers that generate this array;
  • 00, if mm can be arbitrary large;
  • the maximum value mm and any appropriate cc (0≤c<m0 \leq c \lt m) in other cases.

对每个数组,输出:

  • −1-1,如果不存在能生成该数组的四个数;
  • 00,如果 mm 可以任意大;
  • 其他情况下,输出最大的 mm 值及任意一个合适的 cc(满足 0≤c<m0 \leq c \lt m)。

输入输出样例

  • 输入#1

    6
    6
    1 9 17 6 14 3
    3
    4 2 2
    3
    7 3 4
    3
    2 2 4
    5
    0 1000000000 0 1000000000 0
    2
    1 1

    输出#1

    19 8
    -1
    -1
    -1
    2000000000 1000000000
    0

输入解题思路,AI测评打分。不知道怎么写?

首页