MinDifference
SRM 398 · 2008-04-15 · by boba5551
SRM 398 · 2008-04-15 · by boba5551 · Simple Search, Iteration, Sorting
Problem Statement
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.
Constraints
- A0, X, Y, M will each be between 1 and 10000, inclusive.
- n will be between 2 and 10000, inclusive.
Examples
0)
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.
1)
3 9 8 32 8 Returns: 0
All elements are the same.
2)
67 13 17 4003 23 Returns: 14
3)
1 1221 3553 9889 11 Returns: 275
4)
1 1 1 2 10000 Returns: 0
Submissions are judged against all 97 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class MinDifference with a public method int closestElements(int A0, int X, int Y, int M, int n) · 97 test cases · 2 s / 256 MB per case