// vim: filetype=html tabstop=73 background=light :
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")
//#pragma GCC optimize("branch-target-load-optimize")
//#pragma GCC optimize("branch-target-load-optimize2")
//#pragma GCC optimize("btr-bb-exclusive")
//#pragma GCC optimize("O3")

#ifndef __APPLE__
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif

//#include <bits/stdc++.h>

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <deque>
#include <map>
#include <fstream>
#include <utility>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <random>
#include <math.h>
#include <cassert>
#include <bitset>
#include <chrono>
#include <sstream>
#include <array>
#include <list>
#include <functional>
//#include <Python/Python.h>

using namespace std;

#define DEBUG_VIVOD " SHTO-TO POSHLO NE TAK\n"
//#define all(x) x.begin(), x.end()
//#define rall(x) x.rbegin(), x.rend()
//#define pb push_back
//#define pf push_front
//#define _USE_MATH_DEFINES
#define filin(x) freopen(x, "r", stdin)
#define filout(x) freopen(x, "w", stdout)
//#define deq deque
//#define vec vector
//#define umap unordered_map
//#define uset unordered_set
#define nan nullptr
#define endl '\n'
#define INF 1e9 + 2
//#define INF ((int64_t)1e18)
#define INF_LL ((int64_t)1e18)
#define int int64_t

//typedef long long ll;
typedef int64_t ll;
//typedef __int128 ll;
//typedef unsigned long long ull;
//typedef long long ull
typedef long double ull;
//typedef __float128 ull;
//typedef __int128 ull;
typedef long double ld;
typedef unsigned long long ui;

const int maxn = 1e5 + 5, l = 20;

int go[l][maxn];

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> st(maxn, -1);
    vector<int> nxt(n + 1, n);
    for (int i = 0; i < n; ++i) {
        for (int j = 2; j * j <= a[i]; ++j) {
            if (a[i] % j == 0) {
                if (st[j] != -1) {
                    nxt[st[j]] = min(nxt[st[j]], i);
                }
                st[j] = i;
                if (a[i] / j != j) {
                    if (st[a[i] / j] != -1) {
                        nxt[st[a[i] / j]] = min(nxt[st[a[i] / j]], i);
                    }
                    st[a[i] / j] = i;
                }
            }
        }
        if (a[i] > 1) {
            if (st[a[i]] != -1) {
                nxt[st[a[i]]] = min(nxt[st[a[i]]], i);
            }
            st[a[i]] = i;
        }
    }
    vector<int> nxt2(n + 1, n);
    multiset<int> nw;
    int pos = 0;
    for (int i = 0; i < n; ++i) {
        while (pos < n && (nw.size() == 0 || *nw.begin() > pos)) {
            nw.insert(nxt[pos]);
            pos++;
        }
        nxt2[i] = pos;
        nw.erase(nw.find(nxt[i]));
    }
    for (int i = 0; i <= n; ++i) {
        go[0][i] = nxt2[i];
    }
    for (int i = 1; i < l; ++i) {
        for (int j = 0; j <= n; ++j) {
            go[i][j] = go[i - 1][go[i - 1][j]];
        }
    }
    while (q--) {
        int l1, r;
        cin >> l1 >> r;
        l1--;
        int ans = 0;
        for (int i = l - 1; i >= 0; --i) {
            if (go[i][l1] < r) {
                ans += (1 << i);
                l1 = go[i][l1];
            }
        }
        ans++;
        cout << ans << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int q = 1;
//    cin >> q;
    while (q--) {
        solve();
    }
}
