#include <bits/stdc++.h>
using namespace std;
int n, q;

int main()
{
    cin >> n >> q;
    vector<int> a(n), b(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
            if (i > 0)
                b[i] = b[i - 1];
        if (a[i] != pow(2, log2(a[i]))) {
            for (int j = 0; j < n; j++) {
                if (a[j] == pow(2,log2(a[j])) && a[i] > a[j] && a[i] < 2 * a[j])
                    b[i]++;
            }
        }
    }
    while(q--){
        int l, r;
        cin >> l >> r;
        l--, r--;
        int br = b[r] - b[l];
        for (int i = l; i <= r; i++) {
            if (a[i] == pow(2, log2(a[i])))
                br++;
        }
        cout << br << endl;
    }
    return 0;
}