#P5869. Different GCD Subarray Query

Different GCD Subarray Query

Problem Description

This is a simple problem. The teacher gives Bob a list of problems about GCD (Greatest Common Divisor). After studying some of them, Bob thinks that GCD is so interesting. One day, he comes up with a new problem about GCD. Easy as it looks, Bob cannot figure it out himself. Now he turns to you for help, and here is the problem:
  
  Given an array $a$ of $N$ positive integers $a_1, a_2, \cdots a_{N-1}, a_N$; a subarray of $a$ is defined as a continuous interval between $a_1$ and $a_N$. In other words, $a_i, a_{i+1}, \cdots, a_{j-1}, a_j$ is a subarray of $a$, for $1\le i\le j\le N$. For a query in the form $(L, R)$, tell the number of different GCDs contributed by all subarrays of the interval $[L, R]$.
  

Input

There are several tests, process till the end of input.
  
  For each test, the first line consists of two integers $N$ and $Q$, denoting the length of the array and the number of queries, respectively. $N$ positive integers are listed in the second line, followed by $Q$ lines each containing two integers $L,R$ for a query.

You can assume that
  
    $1\le N,Q\le100000$
    
   $1\le a_i\le1000000$

Output

For each query, output the answer in one line.

5 3 1 3 4 6 9 3 5 2 5 1 5
6 6 6