ModuleSequence
SRM 497 · 2010-11-01 · by stone
Problem Statement
You are given four
X[0]=(K*A) MOD N
(note that K*A may overflow a 64-bit integer variable)
X[i]=(X[i-1]+K) MOD N
Given another two
Constraints
- K will be between 0 and 10,000,000,000, inclusive.
- N will be between 1 and 10,000,000,000, inclusive.
- A will be between 0 and 10,000,000,000, inclusive.
- B will be between A and 10,000,000,000, inclusive.
- lower will be between 0 and N-1, inclusive.
- upper will be between lower and N-1, inclusive.
6 4 0 6 1 3 Returns: 3
2 7 1 5 2 5 Returns: 3
The generated list is: 2, 4, 6, 1, 3.
9 1 0 7 0 0 Returns: 8
36 73 1 69 28 34 Returns: 7
30 83 2 24 57 60 Returns: 2
20 12 21 30 1 11 Returns: 6
Note that K, A and B may be greater than N.
9214971511 9875961727 1000000000 9000000000 2500000000 7500000000 Returns: 4050238448
anti Yarin's approach (almost no benefit)
Submissions are judged against all 136 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ModuleSequence with a public method long long countElements(long long K, long long N, long long A, long long B, long long lower, long long upper) · 136 test cases · 2 s / 256 MB per case