PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000149. Cắt dãy thành các đoạn hợp lệ (Cut)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cắt dãy thành các đoạn hợp lệ (Cut)

Cut

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Baby Ehab has a sequence AA of NN positive integers. For a query interval [L,R][L,R], he wants to partition it into nonempty contiguous subarrays, preserving the original order.

A subarray is valid when the product of its elements equals their least common multiple (LCM). For each of QQ independent queries (L,R)(L,R), find the minimum number of valid subarrays needed to cover the interval.

Input

The first line contains N,QN,Q. The second line contains the NN values AiA_i. Each of the next QQ lines contains L,RL,R with 1≤L≤R≤N1\le L\le R\le N.

Output

Print one minimum partition count per query.

Subtasks

  • Subtask 1 (20 points): 1≤N,Q≤301 \le N,Q \le 30; 1≤Ai≤1001 \le A_i \le 100.
  • Subtask 2 (30 points): 1≤N,Q≤50001 \le N,Q \le 5000; 1≤Ai≤1041 \le A_i \le 10^4.
  • Subtask 3 (50 points): 1≤N,Q≤1051 \le N,Q \le 10^5; 1≤Ai≤1051 \le A_i \le 10^5.

Examples

Input

6 3
2 3 10 7 5 14
1 6
2 4
3 5

Output

3
1
2

Explanation

For [1,6][1,6], a valid partition is [2][2], [3,10,7][3,10,7], [5,14][5,14], giving 33 segments. [2,4]=[3,10,7][2,4]=[3,10,7] is already valid. [3,5]=[10,7,5][3,5]=[10,7,5] is invalid because 1010 and 55 both contain the prime 55; it can be split into [10,7][10,7] and [5][5].