#GL0000149. Cắt dãy thành các đoạn hợp lệ (Cut)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 of positive integers. For a query interval , 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 independent queries , find the minimum number of valid subarrays needed to cover the interval.
Input
The first line contains . The second line contains the values . Each of the next lines contains with .
Output
Print one minimum partition count per query.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
6 3
2 3 10 7 5 14
1 6
2 4
3 5
Output
3
1
2
Explanation
For , a valid partition is , , , giving segments. is already valid. is invalid because and both contain the prime ; it can be split into and .