Pitchers#12427

Pitchers

6 seconds
1,024 megabytes
Very hard

An ancient Transcarpathian legend, passed down from generation to generation since time immemorial, says: it is always important to know who you truly are. For anyone who has not discovered their own essence risks drinking water from a magical pitcher and spending the rest of their life barking at passersby. To avoid this fate and finally understand yourself, you need to solve a magical task from the Abkhazian wizard Viktor.

Viktor guards a row of pitchers, each with its own magic number a_i. When you pour a certain number of liters of magical liquid (Domestos) into a pitcher, the curse of divisibility is triggered. If the volume of liquid is divisible by the pitcher's magic number, part of the liquid instantly drains away through the pipes until the remainder is no longer divisible by that number.

More formally: if you pour liters into the pitcher with number a_i, then \frac{k}{a_i^p} liters will remain in it, where is the largest integer such that is divisible by a_i^p. For example, if you pour liters into the pitcher with number , then after the magical transformations only liters will remain.

You are given independent queries. Each query consists of three numbers: , , and . This means that you pour liters of Domestos into each pitcher in the segment from index to index inclusive (indexing starts from zero). Your task is to calculate the total number of liters that will remain in all these pitchers after the magic is applied.

It is important to remember that all queries are independent. This means that before each new query, Viktor carefully washes all the pitchers, and they become completely empty. The previous magic has no effect on the next ritual.

Can you decipher this algorithm and prove to Viktor that you are worthy of knowing your true form, or will you remain forever trapped by Transcarpathian magic?

Input

The first line contains integers and (1 \leq n, Q \leq 3 \cdot 10^6).

The second line contains integers a_i (2 \leq a_i \leq 5 \cdot 10^5).

The next lines contain the numbers l_i, r_i, k_i (1 \leq k \leq 5 \cdot 10^5), (0 \leq l \leq r < n).

Output

In lines, output the total number of liters that will remain in all these pitchers after the magic is applied, for each query.

Examples

Example 1

Loading
Loading

Note

In the first query, l=1, r=3, k=20.

We consider the jugs with indices from to : a_1=5, a_2=3, a_3=10.

For the jug with number : is divisible by , but not divisible by , so \frac{20}{5}=4 will remain.

For the jug with number : is not divisible by , so will remain.

For the jug with number : is divisible by , but not divisible by , so \frac{20}{10}=2 will remain.

Therefore, the answer to the first query is 4+20+2=26.

In the second query, l=0, r=4, k=12.

We consider all jugs: a_0=2, a_1=5, a_2=3, a_3=10, a_4=2.

For the jugs with number : is divisible by 2^2=4, but not divisible by 2^3=8, so \frac{12}{4}=3 will remain in each of them.

For the jug with number : is not divisible by , so will remain.

For the jug with number : is divisible by , but not divisible by , so \frac{12}{3}=4 will remain.

For the jug with number : is not divisible by , so will remain.

Therefore, the answer to the second query is 3+12+4+12+3=34.

In the third query, l=2, r=3, k=100.

We consider the jugs: a_2=3, a_3=10.

For the jug with number : is not divisible by , so will remain.

For the jug with number : is divisible by 10^2=100, so \frac{100}{100}=1 will remain.

Therefore, the answer to the third query is 100+1=101.

Thus, the correct answers for the example are , , .

Scoring

  1. Subtask ( points): (n, Q \le 10^3)

  2. Subtask ( points): (a_i = 2)

  3. Subtask ( points): (a_0 = a_1 = a_2 = \ldots = a_{n - 1})

  4. Subtask ( points): (l_i = 0, r_i = n - 1)

  5. Subtask ( points): (all a_i are prime)

  6. Subtask ( points): (k_0 = k_1 = k_2 = \ldots = k_{Q - 1})

  7. Subtask ( points): (all a_i = 2^k)

  8. Subtask ( points): (n, Q \leq 10^5)

  9. Subtask ( points): Without additional constraints