On friendship day , Thundercracker gifted Tihor an array A of N positive integers instead of chocolates. In order to get the chocolates, Tihor has to solve the following problem given by Thundercracker efficiently:
Thundercracker asks Tihor Q queries. In each query, you are given two integers L and R. You have to compute and print the value of below expression:
(∏P∏Pd|(A[L]..A[R])ϕ(P))%(109+7)
Tihor is worried and find this problem very difficult. Will you help him?
The first line contains N and Q, number of elements in an array A and number of queries respectively.
Second line contains N space separated integers, ith of them denotes A[i].
Third line contains four space separated integers α, β, γ, δ.
You need to generate Q queries in the following way.
Let Ansi denote the answer for ith query and Ans0=0. Then for ith(i≥1) query,
Li = 1+(α∗Ansi−1+i∗β)%N.
Ri = Li+(γ∗Ansi−1+i∗δ)%(N−Li+1).
For each query, print the required answer in a singe line.
1≤N≤105
1≤Q≤106
1≤A[i]≤105
0≤α,β,γ,δ≤109
Subtask | Points |
---|---|
α=γ=0 | 20% |
1≤N,Q,A[i]≤103 | 20% |
Original Constraints | 60% |
The queries are as follows:
For first query, [2,2]- the only prime power which divides subarray [2,2] is 191. So the answer is ϕ(19)=18.
For second query, [1,3]- the prime powers which divides the subarray are 21, 31, 32, 51 and 191. So the answer is 288.