Problem: We call an array b_1, b_2, …, b_m good, if there exist two indices i < j such that b_i ⋅ b_j is a [perfect square](https://en.wikipedia.org/wiki/Square_number).

Given an array b_1, b_2, …, b_m, in one action you can perform one of the following: 

  * multiply any element b_i by any prime p; 
  * divide any element b_i by prime p, if b_i is divisible by p. 



Let f(b_1, b_2, …, b_m) be the minimum number of actions needed to make the array b good.

You are given an array of n integers a_1, a_2, …, a_n and q queries of the form l_i, r_i. For each query output f(a_{l_i}, a_{l_i + 1}, …, a_{r_i}).

Input

The first line contains two integers n and q (2 ≤ n ≤ 194 598, 1 ≤ q ≤ 1 049 658) — the length of the array and the number of queries.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 5 032 107) — the elements of the array.

Each of the next q lines contains two integers l_i and r_i (1 ≤ l_i < r_i ≤ n) — the parameters of a query.

Output

Output q lines — the answers for each query in the order they are given in the input.

Example

Input

10 10
34 37 28 16 44 36 43 50 22 13
1 3
4 8
6 10
9 10
3 10
8 9
5 6
1 4
1 7
2 6


Output

2
0
1
3
0
1
1
1
0
0

Note

In the first query of the first sample you can multiply second number by 7 to get 259 and multiply the third one by 37 to get 1036. Then a_2 ⋅ a_3 = 268 324 = 518^2.

In the second query subarray is already good because a_4 ⋅ a_6 = 24^2.

In the third query you can divide 50 by 2 to get 25. Then a_6 ⋅ a_8 = 30^2.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXVAL = 5e6 + 50e3;
const int MAXN = 2e5 + 10;
const int MAXQ = 1e6 + 55e3;
const int INF = 1e8;
int n, q, a[MAXN];
int tl[MAXQ], tr[MAXQ], sec[MAXQ], ans[MAXQ];
bool mark[MAXVAL], mark2[MAXVAL];
int cnt[MAXVAL];
vector<int> vec[MAXVAL];
int svMask[MAXN], svMaskFirst[MAXN];
bool cmp(int q1, int q2) { return tr[q1] < tr[q2]; }
int seg[MAXN << 2];
int curMn[MAXN];
void upd(int v, int b, int e, int pos, int val) {
  if (e - b == 1) {
    seg[v] = curMn[b] = val;
    return;
  }
  int mid = b + e >> 1;
  if (pos < mid)
    upd(v << 1, b, mid, pos, val);
  else
    upd(v << 1 ^ 1, mid, e, pos, val);
  seg[v] = min(seg[v << 1], seg[v << 1 ^ 1]);
}
int get(int v, int b, int e, int l, int r) {
  if (l <= b && e <= r) return seg[v];
  if (r <= b || e <= l) return INF;
  int mid = b + e >> 1;
  return min(get(v << 1, b, mid, l, r), get(v << 1 ^ 1, mid, e, l, r));
}
unsigned long long hs[MAXN];
vector<pair<int, int> > mpVec[MAXVAL];
void updPosAns(int pos) {
  int val = a[pos];
  int sz = vec[val].size();
  for (int mask = 0; mask < 1 << sz; mask++) {
    if (mask)
      hs[mask] =
          hs[mask ^ 1 << svMaskFirst[mask]] * vec[val][svMaskFirst[mask]];
    else
      hs[mask] = 1;
    int _hs = hs[mask];
    if (mpVec[_hs].size()) {
      int t = sz - svMask[mask];
      auto &v = mpVec[_hs];
      for (auto x : v)
        if (curMn[x.second] > t + x.first) upd(1, 0, n, x.second, t + x.first);
    }
  }
}
void addPos(int pos) {
  int val = a[pos];
  int sz = vec[val].size();
  for (int mask = 0; mask < 1 << sz; mask++) {
    int _hs = hs[mask];
    auto &v = mpVec[_hs];
    pair<int, int> cur(sz - svMask[mask], pos);
    while (v.size() && v.back().first >= cur.first) v.pop_back();
    v.push_back(cur);
  }
}
void findAns(int qu) { ans[qu] = get(1, 0, n, tl[qu], tr[qu]); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(curMn, 63, sizeof(curMn));
  for (int i = 0; i < MAXN; i++) {
    svMask[i] = __builtin_popcount(i);
    if (i) {
      svMaskFirst[i] = 0;
      while (!(i >> svMaskFirst[i] & 1)) svMaskFirst[i]++;
    }
  }
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i], mark2[a[i]] = true;
  for (int i = 2; i < MAXVAL; i++)
    if (!mark[i]) {
      for (int j = i; j < MAXVAL; j += i) {
        mark[j] = true;
        if (!mark2[j]) continue;
        int temp = j, cur = 0;
        while (temp % i == 0) {
          temp /= i;
          cur ^= 1;
        }
        if (cur) cnt[j]++;
      }
    }
  for (int i = 0; i < MAXVAL; i++) vec[i].resize(cnt[i]);
  memset(mark, 0, sizeof(mark));
  for (int i = 2; i < MAXVAL; i++)
    if (!mark[i]) {
      for (int j = i; j < MAXVAL; j += i) {
        mark[j] = true;
        if (!mark2[j]) continue;
        int temp = j, cur = 0;
        while (temp % i == 0) {
          temp /= i;
          cur ^= 1;
        }
        if (cur) vec[j][--cnt[j]] = i;
      }
    }
  for (int i = 0; i < q; i++) cin >> tl[i] >> tr[i], tl[i]--;
  iota(sec, sec + q, 0);
  sort(sec, sec + q, cmp);
  memset(seg, 63, sizeof(seg));
  int cur = 0;
  for (int i = 0; cur < q && i < n; i++) {
    updPosAns(i);
    while (cur < q && tr[sec[cur]] == i + 1) findAns(sec[cur++]);
    addPos(i);
  }
  for (int i = 0; i < q; i++) cout << ans[i] << "\n";
  return 0;
}