#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> t(2 * n);
    map<int, vector<int>> pos;
    for (int i = 0; i < n; i++) {
        cin >> t[n + i];
        pos[t[n + i]].push_back(i);
    }
    for (int i = n - 1; i; i--)
        t[i] = gcd(t[i * 2], t[i * 2 + 1]);
    int q;
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        --l;
        int g = 0;
        for (int a = l + n, b = r + n; a < b; a /= 2, b /= 2) {
            if (a & 1)
                g = gcd(g, t[a++]);
            if (b & 1)
                g = gcd(g, t[--b]);
        }
        auto it = pos.find(g);
        int count = 0;
        if (it != pos.end()) {
            auto &v = it->second;
            count = lower_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l);
        }
        cout << r - l - count << '\n';
    }
}
