Problem Statement
You are given numbers A0, X, Y, M and n.
Generate a list A of length n according to the following recurrence relation:
A[0] = A0
A[i] = (A[i - 1] * X + Y) MOD M, for 0 < i < n
Return the minimal absolute difference between any two elements of A.
Definition
- Class:
- MinDifference
- Method:
- closestElements
- Parameters:
- int, int, int, int, int
- Returns:
- int
- Method signature:
- int closestElements(int A0, int X, int Y, int M, int n)
- (be sure your method is public)
Constraints
- A0, X, Y, M will each be between 1 and 10000, inclusive.
- n will be between 2 and 10000, inclusive.
Examples
3
7
1
101
5
Returns: 6
The elements of the list are {3, 22, 54, 76, 28}. The minimal difference is between elements 22 and 28.3
9
8
32
8
Returns: 0
All elements are the same.67
13
17
4003
23
Returns: 14
1
1221
3553
9889
11
Returns: 275
1
1
1
2
10000
Returns: 0
1567
5003
9661
8929
43
Returns: 14