You are given numbers A0, X, Y, M and n.
Generate a list A of length n using the following recursive definition:
A[0] = A0
A[i] = (A[i - 1] * X + Y) MOD M (note that A[i - 1] * X + Y may overflow 32-bit integer)
Let s(i, k) be a sum of k consecutive elements of the list A starting with the element at
position i (0 indexed).
More formally, s(i, k) = A[i] + A[i + 1] + ... + A[i + k - 1].
Your task is to find the smallest difference between s(i, k) and s(j, k)
(where difference is defined as abs(s(i, k) - s(j, k))) such that
i + k <= j.
In other words, you must find the smallest difference between two subsequences of the same
length that do not overlap.
Call this smallest difference val, and return a int[] containing exactly two elements.
The first element should be k, and the second element should be val.
If there are multiple solutions with the same val, return the one among them with the highest k.
|