Divisibility Pairs

4

1 votes
Medium
Problem

Anurag has a permutation of integers in range [1,N] denoted by A. A permutation is a sequence of all integers in given range and all integers in sequence are distinct, ie, each integer in range occurs exactly once.

Now, he asks Q queries, each one denoted by 2 intgers L and R. For each query, you must find the number of pairs of indices i and j, such that--

  • Ai divides Aj

  • Li,jR

Input Format:

First line contains N and Q, length of sequence and number of queries respectively.

Second line contains N integers denoting the sequence.

Each of the next Q lines contains L and R denoting the query.

Output Format:

For each query, output the required answer in separate lines.

Constraints:

1N,Q105

1AiN

1LRN

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For first query, pairs of values are (4, 4), (3, 3), (1, 1), (5, 5), (1, 4), (1, 3), (1, 5).

For second query, pairs of values are (3, 3), (1, ,1), (5, 5), (2, 2), (1, 3), (1, 5), (1, 2).

for third query, pairs of values are (5, 5), (2, 2).

Editor Image

?