//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")

#include <bits/stdc++.h>

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

template<typename T>
bool umin(T &a, T b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
bool umax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifdef KIVI
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define DEBUG while (false)
#define LOG(...)
#endif

const int max_n = 2e5 + 11, inf = 1000111222;

const int max_k = 6e6 + 11;

template <class T>
struct fenwick {
public:
    int n;
    vector <T> t; /// !!!


    fenwick (int n) : n(n) {
        t.assign(n, T(0));
    }

    inline void upd (int i, T x) {
        for (; i < n; i = i | (i + 1)) {
            if (!umax(t[i], x)) {
                return;
            }
        }
    }

    inline T sum (int r) {
        T ans = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1) umax(ans, t[r]);
        return ans;
    }

};

int mn[max_k], a[max_n], l[max_n], r[max_n], n, q;

ll ans[max_n];

vector <pair<pii, pii> > d[max_k];
int pp[max_k];
vector <pii> have[max_n];
vector <pair<int, ll> > add[max_n];
ll pref[max_n];

vector <int> qq[max_n];



inline void solve () {
    for (int i = 0; i < q; i++) {
        qq[l[i]].pb(i);
    }
    for (int i = 0; i < n; i++) {
        int x = a[i];
        while (x > 1) {
            int y = mn[x], cnt = 0;
            while (x % y == 0) {
                x /= y;
                ++cnt;
            }
            d[y].pb({{i, cnt}, {n + 1, n + 1}});
        }
        pref[i] = a[i];
        if (i) {
            pref[i] += pref[i - 1];
        }
    }
    stack <int> Q;
    for (int i = 2; i < max_k; i++) {
        if (d[i].empty()) {
            continue;
        }
        for (int j = len(d[i]) - 1; j >= 0; j--) {
            if (j + 1 < len(d[i]) && d[i][j].first.first + 1 == d[i][j + 1].first.first) {
                d[i][j].second.first = d[i][j + 1].second.first;
            }
            else {
                d[i][j].second.first = d[i][j].first.first + 1;
            }
            while (!Q.empty() && d[i][Q.top()].first.second >= d[i][j].first.second) {
                Q.pop();
            }
            if (!Q.empty()) {
                d[i][j].second.second = Q.top();
            }
            Q.push(j);
        }
        while (!Q.empty()) Q.pop();
    }

    auto get_sum = [&] (int l, int r) {
        return pref[r] - (l ? pref[l - 1] : 0ll);
    };
    for (int i = 0; i < n; i++) {
        have[i].pb({i, a[i]});
        while (!have[i].empty()) {
            int L = have[i].back().first;
            int g = have[i].back().second;
            have[i].pop_back();
            int to = n, G = g;
            while (g > 1) {
                int y = mn[g], cnt = 0;
                while (g % y == 0) {
                    g /= y;
                    ++cnt;
                }
                // first less than cnt
                while (pp[y] < len(d[y]) && d[y][pp[y]].first.first < i) {
                    ++pp[y];
                }
                int now = i + 1;
                if (pp[y] < len(d[y]) && d[y][pp[y]].first.first == i) {
                    int pos = pp[y];
                    while (pos < len(d[y]) && d[y][pos].first.second >= cnt) {
                        pos = d[y][pos].second.second;
                    }
                    if (pos >= len(d[y])) {
                        pos = len(d[y]) - 1;
                    }
                    else {
                        --pos;
                        umax(pos, 0);
                    }
                    now = max(i + 1, d[y][pos].first.first + 1);

                    umin(now, d[y][pp[y]].second.first);
                }
                umin(to, now);
            }
            if (to < n) {
                assert(G != gcd(G, a[to]));
                have[to].pb({L, gcd(G, a[to])});
            }
            add[L].pb({to - 1, G});
        }
    }
    fenwick <ll> T(n);
    auto upd = [&] (int R, ll val) {
//        R = n - 1 - R;
        T.upd(R, val);
    };
    auto query = [&] (int R) {
//        R = n - 1 - R;
        return T.sum(R);
    };
    for (int i = n - 1; i >= 0; i--) {
        LOG(i);
        for (auto &j : add[i]) {
            upd(j.first, j.second * get_sum(i, j.first));
            LOG(i, j.first, j.second, j.second * get_sum(i, j.first));
        }
        for (auto &j : qq[i]) {
            int R = r[j];
            ll s = get_sum(i, R);
            ll G = -1;
            for (auto &k : add[i]) {
                if (k.first >= R) {
                    G = k.second;
                    break;
                }
            }
            assert(G != -1);
            LOG(G, s * G, j);
            umax(ans[j], s * G);
            umax(ans[j], query(R));
        }
    }
    memset(pp, 0, sizeof(pp));
    for (int i = 0; i < max_k; i++) {
        d[i].clear();
    }
    for (int i = 0; i <= n; i++) {
        add[i].clear();
        qq[i].clear();
        have[i].clear();
    }
}

const int debug = 0;

mt19937 rng(228);
template<typename T = int>
inline T randll(T l = INT_MIN, T r = INT_MAX) {
    return uniform_int_distribution<T>(l, r)(rng);
}

inline ld randld(ld l = INT_MIN, ld r = INT_MAX) {
    return uniform_real_distribution<ld>(l, r)(rng);
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    for (int i = 2; i < max_k; i++) {
        if (!mn[i]) {
            for (int j = i; j < max_k; j += i) {
                if (!mn[j]) mn[j] = i;
            }
        }
    }

    m1:

    if (!debug) {
        cin >> n >> q;
    }
    else {
        n = q = 5;
    }
    for (int i = 0; i < n; i++) {
        if (!debug) {
            cin >> a[i];
        }
        else {
            a[i] = randll(1, 10);
        }
    }
    for (int i = 0; i < q; i++) {
        if (!debug) {
            cin >> l[i] >> r[i];
        }
        else {
            l[i] = randll(1, n);
            r[i] = randll(1, n);
            if (l[i] > r[i]) {
                swap(l[i], r[i]);
            }
        }
        --l[i], --r[i];
    }
    LOG("here");
    solve();
//    for (int i = 0; i < q; i++) {
//        tie(l[i], r[i]) = make_pair(n - 1 - r[i], n - 1 - l[i]);
//    }
//    reverse(a, a + n);
//    solve();
//    reverse(a, a + n);
//    for (int i = 0; i < q; i++) {
//        tie(l[i], r[i]) = make_pair(n - 1 - r[i], n - 1 - l[i]);
//    }
    auto stupid = [&] (int l, int r) {
        ll ans = 0;
        for (int i = l; i <= r; i++) {
            ll s = 0, g = a[i];
            for (int j = i; j <= r; j++) {
                s += a[j];
                g = gcd(g, a[j]);
                umax(ans, s * g);
            }
        }
        return ans;
    };
    for (int i = 0; i < q; i++) {
        cout << ans[i] << '\n';
        if (debug) {
            LOG(ans[i], stupid(l[i], r[i]));
            if (ans[i] != stupid(l[i], r[i])) {
                LOG(n, q);
                for (int j = 0; j < n; j++) LOG(a[j]);
                for (int j = 0; j < q; j++) {
                    LOG(l[j], r[j]);
                }
                exit(3);
            }
        }
    }
    if (debug) {
        memset(ans, 0, sizeof(ans));
        goto m1;
    }
}