F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Different GCD Subarray Query

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2484    Accepted Submission(s): 901


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.
 

Sample Input
5 3 1 3 4 6 9 3 5 2 5 1 5
 

Sample Output
6 6 6
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-17 03:07:17, Gzip enabled