Universal Cup Judging System

Universal Cup

حد الوقت: 3.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

You are given an array $a$ of length $n$.

We define the value of an interval $[l, r]$ as

$$\max_{\substack{l \le i < j < k \le r \\ j-i \le k-j}} \gcd(a_i, a_j, a_k)$$

If $r - l \le 1$, the value is $0$.

There will be $q$ queries. In each query, you need to find the value of a particular interval.

Input

The first line contains two integers $n$ and $q$ ($3 \le n \le 1.5 \times 10^5$, $1 \le q \le 10^5$).

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$).

Each of the next $q$ lines contains two integers $l$ and $r$ ($1 \le l \le r \le n$).

Output

For each query, output one line, an integer, the value of the interval.

Examples

Input 1

8 8
8 24 4 6 6 7 3 3
1 5
2 6
3 7
5 8
4 8
1 3
2 5
3 8

Output 1

4
2
3
1
3
4
2
3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.