Let h(y)
be the function defined as (a*y+b)mod m
. So h(y)
can take values from 0 to m-1.
Now we are given 7 integers- a,b,x,n,c,d,m
. Our task is to find the total count of h(x),h(x+1),h(x+2)...h(x+n)
such that the value of h(x+i)
falls in the range of [c,d]
.where 0<=i<=n
Integer limits are:
1 ≤ m ≤ 10^15, c ≤ d < m, a,b < m, x+n ≤ 10^15, and a*(x+n) + b ≤ 10^15
For Example.
for input set {1,0,0,8,0,8,9}
the output should be 9. Please suggest an efficient algorithm. Thanks!!!