#P5624. [Celeste-A] Black Moonrise
[Celeste-A] Black Moonrise
Description
In Madeline’s dream, the border of the city is made up of cosmic fragments of various sizes.
Each cosmic fragment has an energy value. Because the fragments vary in size, their energy values can be large or small.
Madeline enjoys moving between fragments. Each time, she chooses two cosmic fragments and gains a happiness value equal to the greatest common divisor of their energy values. Note that the two fragments can be the same.
The cosmic fragments form a sequence . Each time, Madeline chooses an interval of this sequence, and for any two cosmic fragments inside this interval, she will move between them once. Note that here is an ordered pair.
Formally, the happiness value Madeline gains each time is
When Madeline is awakened from her dream, she finds that all cosmic fragments have disappeared. She cannot remember the happiness value she got from each move in the dream, and only vaguely remembers the intervals she chose.
So she comes to you, an informatics expert, and asks you to restore the happiness value she obtained at that time based on the intervals she chose each time.
Input Format
The first line contains two positive integers , representing the number of fragments and the number of queries.
The second line contains positive integers , representing the energy value of each fragment.
The next lines each contain two integers , representing the interval Madeline chose in the -th query.
Output Format
For each query, output one line representing the total sum of happiness values Madeline obtains in that query.
5 2
1 2 3 4 5
1 2
2 3
5
7
Hint
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
It is guaranteed that both the sequence and the queries are generated randomly.
Translated by ChatGPT 5
京公网安备 11011102002149号