GCDispower

TimeLimit:5000MS  MemoryLimit:65536KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
There is a mysterious organization called GCD. They get a permutation P, permutation is a sequence of length N, only consists of number 1 to N and each number appears only once.
They want to gain magic power from this permutation. For the interval [L, R] they can get power:
$\sum\limits_{i=L}^R\sum\limits_{j=i+1}^R\sum\limits_{k=j+1}^R (gcd(P[i], P[j]) == P[k]) \cdot P[k]$
Now they have M queries, for each query can you help them calculate how many power they can get?
Input
The first line is an integer T which indicates the case number.
And as for each case, first line is two integer N and M which indicates the length of permutation and number of query.
Next line is N integer which indicate the permutation P
Next M line, for each line is two integer L and R which indicate each query.

Limit
$1 \leq T \leq 100$
$1 \leq N, M \leq100000$
$1 \leq Pi \leq N$, for any pair $(i, j)$, $Pi \neq Pj$
$1 \leq Li \leq Ri \leq N$

About 95% test case: $1 \leq N \leq 1000$
Other test case: $1 \leq N \leq 100000$
Output
As for each case, you need to output M integer which indicate the answer of each query.
SampleInput
2
3 1
3 2 1
1 3
6 3
6 5 4 3 2 1
1 6
2 6
3 5
SampleOutput
1
8
5
0
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数0
总提交量0
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: