Problem Statement | |||||||||||||
You are given four longs K, N, A and B. Generate an integer list X of length B-A+1 using the following recursive definition: 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 longs lower and upper, return the number of elements in the list which are between lower and upper, inclusive. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
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. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|