#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int G = 200005;
int a,z, ps[G], BIT[G], c;
vec<int> rg[G];
map<pii, int> mp;
pii que[G], st[G];

void add(int p, int val){
    for(; p<G; p += p&-p) BIT[p] += val;
}

int prs(int p){
    int o = 0;
    for(; p>0; p -= p&-p) o += BIT[p];
    return o;
}

int main() {
    fast;
    memset(BIT, 0, sizeof(BIT));
    cin>>a>>z;
    for(int q=0; q<a; q++) cin>>c, ps[c] = q+1;
    for(int q=1; q<=a; q++) for(int w=q; w<=a; w+=q) rg[min(ps[q], ps[w])].pb(max(ps[q], ps[w]));
    for(int q=0; q<z; q++) cin>>que[q].F>>que[q].S;
    memcpy(st, que, sizeof(st));
    sort(que, que+z);
    for(int q=z-1, l=a+1; q>=0; q--){
        for(; l>que[q].F; l--) for(int i : rg[l-1]) add(i, 1);
        mp[que[q]] = prs(que[q].S)-prs(que[q].F-1);
    }
    for(int q=0; q<z; q++) cout<<mp[st[q]]<<"\n";
}


#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int G = 200005;
int a,z;
int m[G], ps[G], BIT[G];
vec<int> rg[G];
pii que[G];

inline void add(int p, int val){
    for(; p<G; p += p&-p) BIT[p] += val;
}

inline int prs(int p){
    int o = 0;
    for(; p>0; p -= p&-p) o += BIT[p];
    return o;
}

int main() {
    fast;
    memset(BIT, 0, sizeof(BIT));
    cin>>a>>z;
    for(int q=0; q<a; q++){
        cin>>m[q];
        ps[m[q]] = q+1;
    }
    for(int q=1; q<=a; q++){
        for(int w=q; w<=a; w+=q){
            rg[min(ps[q], ps[w])].pb(max(ps[q], ps[w]));
        }
    }
    for(int q=0; q<z; q++) cin>>que[q].F>>que[q].S;
    pii st[G];
    memcpy(st, que, sizeof(st));
    sort(que, que+z);
    int l = a+1;
    map<pii, int> mp;
    for(int q=z-1; q>=0; q--){
        for(; l>que[q].F; ){
            l--;
            for(int i : rg[l]) add(i, 1);
        }
        int o = prs(que[q].S)-prs(que[q].F-1);
        mp[que[q]] = o;
    }
    for(int q=0; q<z; q++){
        cout<<mp[st[q]]<<"\n";
    }
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename T>
class BIT {
   public:
    BIT(int n) : N(n), A(n + 1, 0) {}

    T sum(int i) {
        T res = 0;
        while (i > 0) {
            res += A[i];
            i -= i & (-i);
        }
        return res;
    }

    T sum(int i, int j) {
        return sum(j) - sum(i - 1);
    }

    void add(int i, T x) {
        while (i <= N) {
            A[i] += x;
            i += (i & (-i));
        }
    }

   private:
    vector<T> A;
    int N;
};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int> A(n), idxs(n + 1);
    REP(i, 0, n) cin >> A[i], idxs[A[i]] = i;

    vector<vector<int>> P(n);
    REP(i, 0, n) {
        for (int j = A[i]; j <= n; j += A[i]) {
            if (idxs[j] <= i) P[i].push_back(idxs[j]);
            else P[idxs[j]].push_back(i);
        }
    }

    vector<int> L(m), R(m), ans(m);
    vector<vector<int>> Q(n);
    REP(i, 0, m) {
        cin >> L[i] >> R[i];
        Q[R[i] - 1].push_back(i);
    }

    // REP(i, 0, n) {
    //     cout << "# i : " << i << " : " << A[i] << " === ";
    //     for (auto p : P[i]) cout << "A[" << p << "]:" << A[p] << " ";
    //     cout << endl;
    // }

    BIT<int> bit(n);
    REP(i, 0, n) {
        for (auto p : P[i]) bit.add(p + 1, 1);
        for (auto q : Q[i]) {
            // ans[q] = bit.sum(n) - bit.sum(L[q] - 1);
            ans[q] = bit.sum(L[q], n);
            // cout << "# Answer for : " << q << " : " << ans[q] << endl;
        }
    }

    for (auto a : ans) cout << a << endl;

    return 0;
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename T>
class BIT {
   public:
    BIT(int n) : N(n), A(n + 1, 0) {}

    T sum(int i) {
        T res = 0;
        while (i > 0) {
            res += A[i];
            i -= i & (-i);
        }
        return res;
    }

    T sum(int i, int j) {
        return sum(j) - sum(i - 1);
    }

    void add(int i, T x) {
        while (i <= N) {
            A[i] += x;
            i += (i & (-i));
        }
    }

   private:
    vector<T> A;
    int N;
};

int main() {
    int n, m; cin >> n >> m;
    vector<int> A(n), idxs(n + 1);
    REP(i, 0, n) cin >> A[i], idxs[A[i]] = i;

    vector<vector<int>> P(n);
    REP(i, 0, n) {
        for (int j = A[i]; j <= n; j += A[i]) {
            if (idxs[j] <= i) P[i].push_back(idxs[j]);
            else P[idxs[j]].push_back(i);
        }
    }

    vector<int> L(m), R(m), ans(m);
    vector<vector<int>> Q(n);
    REP(i, 0, m) {
        cin >> L[i] >> R[i];
        Q[R[i] - 1].push_back(i);
    }

    // REP(i, 0, n) {
    //     cout << "# i : " << i << " : " << A[i] << " === ";
    //     for (auto p : P[i]) cout << "A[" << p << "]:" << A[p] << " ";
    //     cout << endl;
    // }

    BIT<int> bit(n);
    REP(i, 0, n) {
        for (auto p : P[i]) bit.add(p + 1, 1);
        for (auto q : Q[i]) {
            // ans[q] = bit.sum(n) - bit.sum(L[q] - 1);
            ans[q] = bit.sum(L[q], n);
            // cout << "# Answer for : " << q << " : " << ans[q] << endl;
        }
    }

    for (auto a : ans) cout << a << endl;

    return 0;
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename T>
class BIT {
   public:
    BIT(int n) : N(n), A(n + 1, 0) {}

    T sum(int i) {
        T res = 0;
        while (i > 0) {
            res += A[i];
            i -= i & (-i);
        }
        return res;
    }

    T sum(int i, int j) {
        return sum(j) - sum(i - 1);
    }

    void add(int i, T x) {
        while (i <= N) {
            A[i] += x;
            i += (i & (-i));
        }
    }

   private:
    vector<T> A;
    int N;
};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int> A(n), idxs(n + 1);
    REP(i, 0, n) cin >> A[i], idxs[A[i]] = i;

    vector<vector<int>> P(n);
    REP(i, 0, n) {
        for (int j = A[i]; j <= n; j += A[i]) {
            if (idxs[j] <= i) P[i].push_back(idxs[j]);
            else P[idxs[j]].push_back(i);
        }
    }

    vector<int> L(m), R(m), ans(m);
    vector<vector<int>> Q(n);
    REP(i, 0, m) {
        cin >> L[i] >> R[i];
        Q[R[i] - 1].push_back(i);
    }

    // REP(i, 0, n) {
    //     cout << "# i : " << i << " : " << A[i] << " === ";
    //     for (auto p : P[i]) cout << "A[" << p << "]:" << A[p] << " ";
    //     cout << endl;
    // }

    BIT<int> bit(n);
    REP(i, 0, n) {
        for (auto &p : P[i]) bit.add(p + 1, 1);
        for (auto &q : Q[i]) {
            // ans[q] = bit.sum(n) - bit.sum(L[q] - 1);
            ans[q] = bit.sum(L[q], n);
            // cout << "# Answer for : " << q << " : " << ans[q] << endl;
        }
    }

    for (auto &a : ans) cout << a << endl;

    return 0;
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename T>
class BIT {
   public:
    BIT(int n) : N(n), A(n + 1, 0) {}

    T sum(int i) {
        T res = 0;
        while (i > 0) {
            res += A[i];
            i -= i & (-i);
        }
        return res;
    }

    T sum(int i, int j) {
        return sum(j) - sum(i - 1);
    }

    void add(int i, T x) {
        while (i <= N) {
            A[i] += x;
            i += (i & (-i));
        }
    }

   private:
    vector<T> A;
    int N;
};

int main() {
    int n, m; cin >> n >> m;
    vector<int> A(n), idxs(n + 1);
    REP(i, 0, n) cin >> A[i], idxs[A[i]] = i;

    vector<vector<int>> P(n);
    REP(i, 0, n) {
        for (int j = A[i]; j <= n; j += A[i]) {
            if (idxs[j] <= i) P[i].push_back(idxs[j]);
            else P[idxs[j]].push_back(i);
        }
    }

    vector<int> L(m), R(m), ans(m);
    vector<vector<int>> Q(n);
    REP(i, 0, m) {
        cin >> L[i] >> R[i];
        Q[R[i] - 1].push_back(i);
    }

    // REP(i, 0, n) {
    //     cout << "# i : " << i << " : " << A[i] << " === ";
    //     for (auto p : P[i]) cout << "A[" << p << "]:" << A[p] << " ";
    //     cout << endl;
    // }

    BIT<int> bit(n);
    REP(i, 0, n) {
        for (auto p : P[i]) bit.add(p + 1, 1);
        for (auto q : Q[i]) {
            ans[q] = bit.sum(n) - bit.sum(L[q] - 1);
            // cout << "# Answer for : " << q << " : " << ans[q] << endl;
        }
    }

    for (auto a : ans) cout << a << endl;

    return 0;
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename T>
class BIT {
   public:
    BIT(int n) : N(n), A(n + 1, 0) {}

    T sum(int i) {
        T res = 0;
        while (i > 0) {
            res += A[i];
            i -= i & (-i);
        }
        return res;
    }

    T sum(int i, int j) {
        return sum(j) - sum(i - 1);
    }

    void add(int i, T x) {
        while (i <= N) {
            A[i] += x;
            i += (i & (-i));
        }
    }

   private:
    vector<T> A;
    int N;
};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int> A(n), idxs(n + 1);
    REP(i, 0, n) cin >> A[i], idxs[A[i]] = i;

    vector<vector<int>> P(n);
    REP(i, 0, n) {
        for (int j = A[i]; j <= n; j += A[i]) {
            if (idxs[j] <= i) P[i].push_back(idxs[j]);
            else P[idxs[j]].push_back(i);
        }
    }

    vector<int> ans(m);
    vector<vector<pair<int, int>>> Q(n);
    REP(i, 0, m) {
        int l, r; cin >> l >> r;
        Q[--r].push_back({l, i});
    }

    BIT<int> bit(n);
    REP(i, 0, n) {
        for (auto &p : P[i]) bit.add(p + 1, 1);
        for (auto &q : Q[i]) {
            ans[q.second] = bit.sum(q.first, n);
        }
    }

    for (auto &a : ans) cout << a << endl;

    return 0;
}


///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
#include <random>
#include <chrono>
#include <stack>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef long double ld;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef pair<pii , int> piii;
typedef map<string , int> msi;
const int MAXN = 2e5 + 10;
int n , m , p[MAXN] , ind[MAXN] , l[MAXN] , r[MAXN] , cnt[MAXN] , fen[MAXN];
vector<int> query[MAXN] , vec[MAXN];
void update(int p)
{
	for(p ++ ; p <= n ; p += p&-p)
		fen[p] ++;
	return;
}
int get(int p)
{
	int res = 0;
	for( ; p ; p -= p&-p)
		res += fen[p];
	return res;
}
int32_t main()
{
	IOS
	cin >> n >> m;
	for(int i = 0 ; i < n ; i ++)
		cin >> p[i] , ind[p[i]] = i;
	for(int i = 0 ; i < m ; i ++)
		cin >> l[i] >> r[i] , l[i] -- , query[r[i] - 1].pb(i);
	for(int i = 1 ; i <= n ; i ++)
		for(int j = i ; j <= n ; j += i)
			if(ind[i] <= ind[j])
				vec[ind[j]].pb(ind[i]);
			else
				vec[ind[i]].pb(ind[j]);
	for(int i = 0 ; i < n ; i ++)
	{
		for(auto it : vec[i])
			update(it);
		for(auto q : query[i])
			cnt[q] = get(r[q]) - get(l[q]);
	}
	for(int i = 0 ; i < m ; i ++)
		cout << cnt[i] << endl;
	return 0;
}


///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
#include <random>
#include <chrono>
#include <stack>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef long double ld;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef pair<pii , int> piii;
typedef map<string , int> msi;
const int MAXN = 2e5 + 10;
int n , m , p[MAXN] , ind[MAXN] , l[MAXN] , r[MAXN] , cnt[MAXN] , fen[MAXN];
vector<int> query[MAXN] , vec[MAXN];
void update(int p)
{
	for(p ++ ; p < MAXN ; p += p&-p)
		fen[p] ++;
	return;
}
int get(int p)
{
	int res = 0;
	for( ; p ; p -= p&-p)
		res += fen[p];
	return res;
}
int32_t main()
{
	cin >> n >> m;
	for(int i = 0 ; i < n ; i ++)
		cin >> p[i] , ind[p[i]] = i;
	for(int i = 0 ; i < m ; i ++)
		cin >> l[i] >> r[i] , l[i] -- , query[r[i] - 1].pb(i);
	for(int i = 1 ; i <= n ; i ++)
		for(int j = i ; j <= n ; j += i)
			if(ind[i] <= ind[j])
				vec[ind[j]].pb(ind[i]);
			else
				vec[ind[i]].pb(ind[j]);
	for(int i = 0 ; i < n ; i ++)
	{
		for(auto it : vec[i])
			update(it);
		for(auto q : query[i])
			cnt[q] = get(r[q]) - get(l[q]);
	}
	for(int i = 0 ; i < m ; i ++)
		cout << cnt[i] << endl;
	return 0;
}


///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
#include <random>
#include <chrono>
#include <stack>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef long double ld;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef pair<pii , int> piii;
typedef map<string , int> msi;
const int MAXN = 2e5 + 10;
int n , m , p[MAXN] , ind[MAXN] , l[MAXN] , r[MAXN] , cnt[MAXN] , fen[MAXN];
vector<int> query[MAXN] , vec[MAXN];
void update(int p)
{
	for(p ++ ; p <= n ; p += p&-p)
		fen[p] ++;
	return;
}
int get(int p)
{
	int res = 0;
	for( ; p ; p -= p&-p)
		res += fen[p];
	return res;
}
int32_t main()
{
	cin >> n >> m;
	for(int i = 0 ; i < n ; i ++)
		cin >> p[i] , ind[p[i]] = i;
	for(int i = 0 ; i < m ; i ++)
		cin >> l[i] >> r[i] , l[i] -- , query[r[i] - 1].pb(i);
	for(int i = 1 ; i <= n ; i ++)
		for(int j = i ; j <= n ; j += i)
			if(ind[i] <= ind[j])
				vec[ind[j]].pb(ind[i]);
			else
				vec[ind[i]].pb(ind[j]);
	for(int i = 0 ; i < n ; i ++)
	{
		for(auto it : vec[i])
			update(it);
		for(auto q : query[i])
			cnt[q] = get(r[q]) - get(l[q]);
	}
	for(int i = 0 ; i < m ; i ++)
		cout << cnt[i] << endl;
	return 0;
}


///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
#include <random>
#include <chrono>
#include <stack>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef long double ld;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef pair<pii , int> piii;
typedef map<string , int> msi;
const int MAXN = 2e5 + 10;
int n , m , p[MAXN] , ind[MAXN] , l[MAXN] , r[MAXN] , cnt[MAXN] , fen[MAXN];
vector<int> query[MAXN] , vec[MAXN];
void update(int p)
{
	for(p ++ ; p < MAXN ; p += p&-p)
		fen[p] ++;
	return;
}
int get(int p)
{
	int res = 0;
	for( ; p ; p -= p&-p)
		res += fen[p];
	return res;
}
int32_t main()
{
	IOS
	cin >> n >> m;
	for(int i = 0 ; i < n ; i ++)
		cin >> p[i] , ind[p[i]] = i;
	for(int i = 0 ; i < m ; i ++)
		cin >> l[i] >> r[i] , l[i] -- , query[r[i] - 1].pb(i);
	for(int i = 1 ; i <= n ; i ++)
		for(int j = i ; j <= n ; j += i)
			if(ind[i] <= ind[j])
				vec[ind[j]].pb(ind[i]);
			else
				vec[ind[i]].pb(ind[j]);
	for(int i = 0 ; i < n ; i ++)
	{
		for(auto it : vec[i])
			update(it);
		for(auto q : query[i])
			cnt[q] = get(r[q]) - get(l[q]);
	}
	for(int i = 0 ; i < m ; i ++)
		cout << cnt[i] << endl;
	return 0;
}


/*
 * Words like "tomorrow" or "future" or "fate"
 *		No matter how far they extend their hands
 *			We breathe, we dream, we raise our love
 *				In a timeless land that is far out of reach
 */
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#ifndef rd
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
#define double long double
#define pii pair<int,int>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(x) x.begin(),x.end()
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powm(ll a, ll b, ll m);

int a[200001];
vector<pair<pii,int>> queries;
int tr[200001];
int rp[200001];
int anses[200001];
vector<int> delayed[200001];
int nn;
int query(int l, int r)
{
	int sum=0;
	r++;
	for(l+=nn,r+=nn; l<r; l>>=1,r>>=1)
	{
		if(l&1) sum+=tr[l++];
		if(r&1) sum+=tr[--r];
	}
	return sum;
}
void add(int pos)
{
	for(pos+=nn; pos>0; pos>>=1)
		tr[pos]++;
}
signed main()
{
	IO;
	int n,m;
	cin>>n>>m;
	nn=n+1;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(int i=1; i<=n; i++)
		rp[a[i]]=i;
	for(int i=1,u,v; i<=m; i++) {
		cin>>u>>v;
		queries.pb({{v,u},i});
	}
	sort(all(queries));
	int updated=0;
	for(auto te:queries)
	{
		while(updated<te.fi.fi)
		{
			updated++;
			for(int i:delayed[updated])
				add(i);
			for(int i=a[updated]; i<=n; i+=a[updated])
				if(rp[i]<=updated)
					add(rp[i]);
				else
					delayed[rp[i]].pb(updated);
		}
		anses[te.se]=query(te.fi.se,te.fi.fi);
	}
	for(int i=1; i<=m; i++)
		cout<<anses[i]<<endl;
}
ll powm(ll a,ll b, ll m)
{
	ll te=1;
	while(b)
	{
		if(b&1)
			te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


/*
 * Words like "tomorrow" or "future" or "fate"
 *		No matter how far they extend their hands
 *			We breathe, we dream, we raise our love
 *				In a timeless land that is far out of reach
 */
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#ifndef rd
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
#define double long double
#define pii pair<int,int>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(x) x.begin(),x.end()
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powm(ll a, ll b, ll m);

int a[200001];
vector<pair<pii,int>> queries;
int tr[400001];
int rp[200001];
int anses[200001];
vector<int> delayed[200001];
int nn;
int query(int l, int r)
{
	int sum=0;
	r++;
	for(l+=nn,r+=nn; l<r; l>>=1,r>>=1)
	{
		if(l&1) sum+=tr[l++];
		if(r&1) sum+=tr[--r];
	}
	return sum;
}
void add(int pos)
{
	for(pos+=nn; pos>0; pos>>=1)
		tr[pos]++;
}
signed main()
{
	IO;
	int n,m;
	cin>>n>>m;
	nn=n+1;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(int i=1; i<=n; i++)
		rp[a[i]]=i;
	for(int i=1,u,v; i<=m; i++) {
		cin>>u>>v;
		queries.pb({{v,u},i});
	}
	sort(all(queries));
	int updated=0;
	for(auto te:queries)
	{
		while(updated<te.fi.fi)
		{
			updated++;
			for(int i:delayed[updated])
				add(i);
			for(int i=a[updated]; i<=n; i+=a[updated])
				if(rp[i]<=updated)
					add(rp[i]);
				else
					delayed[rp[i]].pb(updated);
		}
		anses[te.se]=query(te.fi.se,te.fi.fi);
	}
	for(int i=1; i<=m; i++)
		cout<<anses[i]<<endl;
}
ll powm(ll a,ll b, ll m)
{
	ll te=1;
	while(b)
	{
		if(b&1)
			te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


/*
 * Words like "tomorrow" or "future" or "fate"
 *		No matter how far they extend their hands
 *			We breathe, we dream, we raise our love
 *				In a timeless land that is far out of reach
 */
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#ifndef rd
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
#define double long double
#define pii pair<int,int>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(x) x.begin(),x.end()
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powm(ll a, ll b, ll m);

int a[200001];
vector<pair<pii,int>> queries;
int tr[200001];
int rp[200001];
int anses[200001];
vector<int> delayed[200001];
int nn;
int query(int l, int r)
{
	int sum=0;
	r++;
	for(l+=nn,r+=nn; l<r; l>>=1,r>>=1)
	{
		if(l&1) sum+=tr[l++];
		if(r&1) sum+=tr[--r];
	}
	return sum;
}
void add(int pos)
{
	for(pos+=nn; pos>0; pos>>=1)
		tr[pos]++;
}
vector<int> divi[200001];
signed main()
{
	IO;
	int n,m;
	cin>>n>>m;
	nn=n+1;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(int i=1; i<=n; i++)
		rp[a[i]]=i;
	for(int i=1,u,v; i<=m; i++) {
		cin>>u>>v;
		queries.pb({{v,u},i});
	}
	for(int i=1; i<=200000; i++)
		for(int j=i; j<=200000; j+=i)
			divi[j].pb(i);
	sort(all(queries));
	int updated=0;
	for(auto te:queries)
	{
		while(updated<te.fi.fi)
		{
			updated++;
			for(int i:divi[a[updated]])
				if(rp[i]<=updated)
					add(rp[i]);
			for(int i=2*a[updated]; i<=n; i+=a[updated])
				if(rp[i]<=updated)
					add(rp[i]);
		}
		anses[te.se]=query(te.fi.se,te.fi.fi);
	}
	for(int i=1; i<=m; i++)
		cout<<anses[i]<<endl;
}
ll powm(ll a,ll b, ll m)
{
	ll te=1;
	while(b)
	{
		if(b&1)
			te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;
#define lowbit(x) (x&(-x))

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, l, r;
int A[MAXN];
int pos[MAXN];
int ans[MAXN];
int BIT[MAXN];
vector<int> vec[MAXN];
vector<pii> query[MAXN];

void add(int id, int x){ for (; id<MAXN; id+=lowbit(id)) BIT[id]+=x;}
int get(int id){
	int res=0;
	for (; id; id-=lowbit(id)) res+=BIT[id];
	return res;
}

void upd(int l, int r){
	if (l>r) swap(l, r);
	vec[l].pb(r);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<=n; i++) cin>>A[i], pos[A[i]]=i;
	for (int i=1; i<=n; i++) for (int j=i; j<MAXN; j+=i) upd(pos[i], pos[j]);
	for (int i=1; i<=m; i++){
		cin>>l>>r;
		query[l].pb({r, i});
	}
	for (int i=n; i; i--){
		for (int x:vec[i]) add(x, 1);
		for (pii p:query[i]) ans[p.second]=get(p.first);
	}
	for (int i=1; i<=m; i++) cout<<ans[i]<<'\n';

	return 0;
}
/*
      ___           ___                            ___           ___           ___           ___           ___           ___
     /\  \         /\__\      ___                 /\  \         /\__\         /\  \         /\__\         /\  \         /\__\      ___
    /::\  \       /:/  /     /\  \               /::\  \       /:/  /        /::\  \       /:/  /        /::\  \       /:/  /     /\  \
   /:/\:\  \     /:/  /      \:\  \             /:/\ \  \     /:/__/        /:/\:\  \     /:/__/        /:/\:\  \     /:/  /      \:\  \
  /::\~\:\  \   /:/  /       /::\__\           _\:\~\ \  \   /::\  \ ___   /::\~\:\  \   /::\  \ ___   /::\~\:\  \   /:/  /       /::\__\
 /:/\:\ \:\__\ /:/__/     __/:/\/__/          /\ \:\ \ \__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/__/     __/:/\/__/
 \/__\:\/:/  / \:\  \    /\/:/  /             \:\ \:\ \/__/ \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \:\  \    /\/:/  /
      \::/  /   \:\  \   \::/__/               \:\ \:\__\        \::/  /       \::/  /       \::/  /       \::/  /   \:\  \   \::/__/
      /:/  /     \:\  \   \:\__\                \:\/:/  /        /:/  /        /:/  /        /:/  /        /:/  /     \:\  \   \:\__\
     /:/  /       \:\__\   \/__/                 \::/  /        /:/  /        /:/  /        /:/  /        /:/  /       \:\__\   \/__/
     \/__/         \/__/                          \/__/         \/__/         \/__/         \/__/         \/__/         \/__/
*/


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define lowbit(x) (x&(-x))

const int MAXN = 200010;

int n, m, x, y, t, l, r;
int pos[MAXN];
int ans[MAXN];
int BIT[MAXN];
vector<int> vec[MAXN];
vector<pii> query[MAXN];

void add(int id, int x){ for (; id<MAXN; id+=lowbit(id)) BIT[id]+=x;}
int get(int id){
	int res=0;
	for (; id; id-=lowbit(id)) res+=BIT[id];
	return res;
}

void upd(int l, int r){
	if (l>r) swap(l, r);
	vec[l].pb(r);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for (int i=1; i<=n; i++) cin>>x, pos[x]=i;
	for (int i=1; i<=n; i++) for (int j=i; j<MAXN; j+=i) upd(pos[i], pos[j]);
	for (int i=1; i<=m; i++){
		cin>>l>>r;
		query[l].pb({r, i});
	}
	for (int i=n; i; i--){
		for (int x:vec[i]) add(x, 1);
		for (pii p:query[i]) ans[p.second]=get(p.first);
	}
	for (int i=1; i<=m; i++) cout<<ans[i]<<'\n';

	return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define lowbit(x) (x&(-x))
#define pb push_back

const int MAXN = 200010;

int n, m, x, y, t, l, r;
int pos[MAXN];
int ans[MAXN];
int BIT[MAXN];
vector<int> vec[MAXN];
vector<pair<int, int>> query[MAXN];

void add(int id, int x){ for (; id<MAXN; id+=lowbit(id)) BIT[id]+=x;}
int get(int id){
	int res=0;
	for (; id; id-=lowbit(id)) res+=BIT[id];
	return res;
}

void upd(int l, int r){
	if (l>r) swap(l, r);
	vec[l].pb(r);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for (int i=1; i<=n; i++) cin>>x, pos[x]=i;
	for (int i=1; i<=n; i++) for (int j=i; j<MAXN; j+=i) upd(pos[i], pos[j]);
	for (int i=1; i<=m; i++){
		cin>>l>>r;
		query[l].pb({r, i});
	}
	for (int i=n; i; i--){
		for (int x:vec[i]) add(x, 1);
		for (auto p:query[i]) ans[p.second]=get(p.first);
	}
	for (int i=1; i<=m; i++) cout<<ans[i]<<'\n';

	return 0;
}


#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;
#define lowbit(x) (x&(-x))

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG=20;

int n, m, k, u, v, x, y, t, l, r;
int A[MAXN];
int pos[MAXN];
int ans[MAXN];
int BIT[MAXN];
vector<int> vec[MAXN];
vector<pii> query[MAXN];

void add(int id, int x){ for (; id<MAXN; id+=lowbit(id)) BIT[id]+=x;}
int get(int id){
	int res=0;
	for (; id; id-=lowbit(id)) res+=BIT[id];
	return res;
}

void upd(int l, int r){
	if (l>r) swap(l, r);
	vec[l].pb(r);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<=n; i++) cin>>A[i], pos[A[i]]=i;
	for (int i=1; i<=n; i++) for (int j=i; j<MAXN; j+=i) upd(pos[i], pos[j]);
	for (int i=1; i<=m; i++){
		cin>>l>>r;
		query[l].pb({r, i});
	}
	for (int i=n; i; i--){
		for (int x:vec[i]) add(x, 1);
		for (pii p:query[i]) ans[p.second]=get(p.first);
	}
	for (int i=1; i<=m; i++) cout<<ans[i]<<'\n';

	return 0;
}
/*
      ___           ___                            ___           ___           ___           ___           ___           ___
     /\  \         /\__\      ___                 /\  \         /\__\         /\  \         /\__\         /\  \         /\__\      ___
    /::\  \       /:/  /     /\  \               /::\  \       /:/  /        /::\  \       /:/  /        /::\  \       /:/  /     /\  \
   /:/\:\  \     /:/  /      \:\  \             /:/\ \  \     /:/__/        /:/\:\  \     /:/__/        /:/\:\  \     /:/  /      \:\  \
  /::\~\:\  \   /:/  /       /::\__\           _\:\~\ \  \   /::\  \ ___   /::\~\:\  \   /::\  \ ___   /::\~\:\  \   /:/  /       /::\__\
 /:/\:\ \:\__\ /:/__/     __/:/\/__/          /\ \:\ \ \__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/__/     __/:/\/__/
 \/__\:\/:/  / \:\  \    /\/:/  /             \:\ \:\ \/__/ \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \:\  \    /\/:/  /
      \::/  /   \:\  \   \::/__/               \:\ \:\__\        \::/  /       \::/  /       \::/  /       \::/  /   \:\  \   \::/__/
      /:/  /     \:\  \   \:\__\                \:\/:/  /        /:/  /        /:/  /        /:/  /        /:/  /     \:\  \   \:\__\
     /:/  /       \:\__\   \/__/                 \::/  /        /:/  /        /:/  /        /:/  /        /:/  /       \:\__\   \/__/
     \/__/         \/__/                          \/__/         \/__/         \/__/         \/__/         \/__/         \/__/
*/


#include <bits/stdc++.h>

#define int long long
#define f first

#define s second
using namespace std;

template<typename T> using vc = vector<T>;
using pii=pair<int, int>;

void xmax(int & a, int b){
    a=max(a, b);
}
void xmin(int& a, int b){
    a=min(a, b);
}

void print(vc <int> & a, string s){
    cerr << s << " : ";
    for (int i=0; i<a.size(); i++){
        cerr <<a[i] << " ";
    }
    cerr << endl;
}
unordered_map <int, int> krat;
vc <vc <int > > fwd;
vc < vc <int> > bk;
int anz = 0;
void add(int x, int mode){
  //  cout << "added at " << x << endl;
    if (mode == 1){
        for (auto ne : fwd[x]){
            krat[ne]++;
            if (krat[ne] == 2) anz++;
        }
    }
    if (mode == -1){
        for (auto ne : bk[x]){
            krat[ne]++;
            if (krat[ne] == 2) anz++;
        }
    }
    if (mode == 2){
        for (auto ne: fwd [x]){
            krat[ne]--;
            if (krat[ne] == 1) anz--;
        }
        for (auto ne: bk[x]){
            krat[ne]--;
            if (krat[ne] == 1) anz--;
        }
    }
    if (mode == -2){
        for(auto ne: fwd[x]) {
            krat[ne]++;
            if (krat[ne] == 2) anz++;
        }
        for (auto ne:bk[x]){
            krat[ne]++;
            if (krat[ne] == 2) anz++;
        }
    }
}
void mo (int a, int itl, int x){
    for (int k =itl; k<a; k++){
        add(k, 2*x);
    }
    for (int k = itl; k>=a; k--){
        add(k, -2*x);
    }

}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL_RUN
    freopen("input.txt", "r", stdin);
    int ttt;
    cin >> ttt;
    while(ttt--){
    #endif // LOCAL_RUN
    int n, q;
    cin >> n >> q;
    vc <int> a (n);
    vc <int> zur (n+1);
    for (int i=0; i<n; i++){
        cin >> a[i];
        zur[a[i]] = i;
    }
    int index = 1;
    fwd = vc <vc <int> >  (n);
    bk = vc <vc <int> > (n);
    for (int i=0; i<n; i++){
        for (int j=2; j*a[i]<=n; j++){
            fwd[min(zur[j*a[i]], i)].push_back(index);
            bk[max(zur[j*a[i]], i)].push_back(index);
            index++;
        }
    }

    int k = 700;

    vc <int> res (q);
    vc <vc <pair <int, pii> > > ev (n/k+1);

    //cout << "da" << endl;
    for (int i=0; i<q; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
       // cout << "ha" << endl;
        //cerr << ev.size() << endl;
        ev[a/k].push_back({b, {a, i}});
    }
   // cout << "hier" << endl;

    krat.clear();
    int itl = 0;
    int itr = 0;
    for (int j=0; j*k<q; j++){
      //  cout << "doing box j " << j << endl;
        sort(ev[j].begin(), ev[j].end());
        krat.clear();
        for (int i=0; i<ev[j].size();i++){
            int a = ev[j][i].s.f;
            int b = ev[j][i].f;
         //   cout << "iterators from " << itl << " " << itr << endl;
          //  cout << " to " << a << " " << b << endl;
           // cout << "what maxi looks like" << endl;
           /* for (auto x: krat){
                cout << x.f << " " << x.s << endl;
            }*/
            mo(a, itl, 1);
            mo(b+1, itr, -1);
            res[ev[j][i].s.s] = anz + b-a+1;
            itl = a;
            itr = b;
        }

    }
    for (int i=0; i<q; i++) cout << res[i] << "\n";
    /*for (int i=0; i<n; i++){
        print(fwd[i], "f");
    }*/

   /* cout << "(I(((((((((((((((((" << endl;
    for (int i=0; i<n; i++){
        print(bk[i] , "b");
    }*/

    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
}


#include <bits/stdc++.h>

#define int long long
#define f first

#define s second
using namespace std;

template<typename T> using vc = vector<T>;
using pii=pair<int, int>;

void print(vc <int> & a, string s){
    cerr << s << " : ";
    for (int i=0; i<a.size(); i++){
        cerr <<a[i] << " ";
    }
    cerr << endl;
}
template<class Segtree_Data>
struct Segment_Tree{
	using T = typename Segtree_Data::node_t;
	int n;
	vector<T>data;
	Segment_Tree(int _n):n(_n), data(2*n, Segtree_Data::node_ne()){
		for(int i=n-1;i>=0;--i) data[i] = Segtree_Data::merge_nodes(data[i<<1], data[i<<1|1]);
	}
	Segment_Tree(vector<T> const&base):n(base.size()), data(2*n, Segtree_Data::node_ne()){
		copy(base.begin(), base.end(), data.begin()+n);
		for(int i=n-1;i>=0;--i) data[i] = Segtree_Data::merge_nodes(data[i<<1], data[i<<1|1]);
	}
	void update(int pos, typename Segtree_Data::update_t const&val){
		for(Segtree_Data::update_node(data[pos+=n], val);pos>>=1;){
			data[pos] = Segtree_Data::merge_nodes(data[pos<<1], data[pos<<1|1]);
		}
	}
	T query(int l, int r)const{
		T retL = Segtree_Data::node_ne(), retR = Segtree_Data::node_ne();
		for(l+=n, r+=n;l<r;l>>=1, r>>=1){
			if(l&1) retL = Segtree_Data::merge_nodes(retL, data[l++]);
			if(r&1) retR = Segtree_Data::merge_nodes(data[--r], retR);
		}
		return Segtree_Data::merge_nodes(retL, retR);
	}
};
struct Segtreedata{
    typedef int node_t;
    typedef int update_t;
    static node_t node_ne() {return 0;}
    static node_t merge_nodes(node_t const&left, node_t const&right){
        return left+right;
    }
    static void update_node(node_t &node, update_t const&update){
        node += update;
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL_RUN
    freopen("input.txt", "r", stdin);
    int ttt;
    cin >> ttt;
    while(ttt--){
    #endif // LOCAL_RUN
    int n, q;
    cin >> n >> q;
    vc <int> a (n);
    vc <int> zur (n+1);
    for (int i=0; i<n; i++){
        cin >> a[i];
        zur[a[i]] = i;
    }
    int index = 1;
    Segment_Tree<Segtreedata> seg (n);
    vc <vc <int> > up (n);
    for (int i=0; i<n; i++){
        for (int j=2; j*a[i]<=n; j++){

            int l = min(zur[j*a[i]], i);
            int r = max(zur[j*a[i]], i);
            up[l].push_back(r);
            seg.update(r, 1);
        }
    }
    vc <vc <pii> > b (n);
    for (int i=0; i<q; i++){
        int c, d;
        cin >> c >> d;
        c--; d--;
        b[c].push_back({d, i});
    }
    vc <int> res (q);
    for (int i=0; i<n; i++){
        for (int j =0;j<b[i].size(); j++){
            int ind = b[i][j].s;
            int d = b[i][j].f;
            res[ind] = d-i+1+seg.query(0, d+1);
        }
        for (int j=0; j<up[i].size(); j++){
            seg.update(up[i][j] ,-1);
        }

    }
    for (int i=0; i<q; i++){
        cout << res[i] << "\n";
    }

    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
}


#include <bits/stdc++.h>

#define int long long
#define f first

#define s second
using namespace std;

template<typename T> using vc = vector<T>;
using pii=pair<int, int>;

void xmax(int & a, int b){
    a=max(a, b);
}
void xmin(int& a, int b){
    a=min(a, b);
}

void print(vc <int> & a, string s){
    cerr << s << " : ";
    for (int i=0; i<a.size(); i++){
        cerr <<a[i] << " ";
    }
    cerr << endl;
}
unordered_map <int, int> krat;
vc <vc <int > > fwd;
vc < vc <int> > bk;
int anz = 0;
void add(int x, int mode){
  //  cout << "added at " << x << endl;
    if (x == -1) return;
    if (mode == 1){
        for (auto ne : fwd[x]){
            krat[ne]++;
            if (krat[ne] == 2) anz++;
        }
    }
    if (mode == -1){
        for (auto ne : bk[x]){
            krat[ne]++;
            if (krat[ne] == 2) anz++;
        }
    }
    if (mode == 2){
        for (auto ne: fwd [x]){
            krat[ne]--;
            if (krat[ne] == 1) anz--;
        }
        for (auto ne: bk[x]){
            krat[ne]--;
            if (krat[ne] == 1) anz--;
        }
    }
    if (mode == -2){
        for(auto ne: fwd[x]) {
            krat[ne]++;
            if (krat[ne] == 2) anz++;
        }
        for (auto ne:bk[x]){
            krat[ne]++;
            if (krat[ne] == 2) anz++;
        }
    }
}
void mo (int a, int itl, int x){
    for (int k =itl+1; k<a; k++){
        add(k, 2*x);
    }
    for (int k = itl; k>=a; k--){
        add(k, -2*x);
    }

}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL_RUN
    freopen("input.txt", "r", stdin);
    int ttt;
    cin >> ttt;
    while(ttt--){
    #endif // LOCAL_RUN
    int n, q;
    cin >> n >> q;
    vc <int> a (n);
    vc <int> zur (n+1);
    for (int i=0; i<n; i++){
        cin >> a[i];
        zur[a[i]] = i;
    }
    int index = 1;
    fwd = vc <vc <int> >  (n);
    bk = vc <vc <int> > (n);
    for (int i=0; i<n; i++){
        for (int j=2; j*a[i]<=n; j++){
            fwd[min(zur[j*a[i]], i)].push_back(index);
            bk[max(zur[j*a[i]], i)].push_back(index);
            index++;
        }
    }

    int k = 700;

    vc <int> res (q);
    vc <vc <pair <int, pii> > > ev (n/k+1);

    //cout << "da" << endl;
    for (int i=0; i<q; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
       // cout << "ha" << endl;
        //cerr << ev.size() << endl;
        ev[a/k].push_back({b, {a, i}});
    }
   // cout << "hier" << endl;

    krat.clear();
    int itl = -1;
    int itr = -1;
    for (int j=0; j*k<q; j++){
      //  cout << "doing box j " << j << endl;
        sort(ev[j].begin(), ev[j].end());
        for (int i=0; i<ev[j].size();i++){
            int a = ev[j][i].s.f;
            int b = ev[j][i].f;
          //  cout << "iterators from " << itl << " " << itr << endl;
           // cout << " to " << a << " " << b << endl;

            mo(a, itl, 1);
            mo(b+1, itr, -1);
            res[ev[j][i].s.s] = anz + b-a+1;
            itl = a-1;
            itr = b;
           /* cout << "what maxi looks like" << endl;
            for (auto x: krat){
                cout << x.f << " " << x.s << endl;
            }*/
        }

    }
    for (int i=0; i<q; i++) cout << res[i] << "\n";
    /*for (int i=0; i<n; i++){
        print(fwd[i], "f");
    }*/

   /* cout << "(I(((((((((((((((((" << endl;
    for (int i=0; i<n; i++){
        print(bk[i] , "b");
    }*/

    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
typedef long long ll;
ll n, m;
ll arr[MAXN];
ll positions[MAXN];
vector <ll> hashes;
ll hash_pair(pair <ll, ll> a)
{
    return a.first * MAXN + a.second;
}
int main()
{
    scanf("%lld%lld", &n, &m);
    for (ll i = 1; i <= n; i++)
        {
            scanf("%lld", &arr[i]);
            positions[arr[i]] = i;
        }
    for (ll i = 1; i <= n; i++)
        for (ll j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
            hashes.push_back(hash_pair(make_pair(positions[j], i)));
    sort (hashes.begin(), hashes.end());
    for (ll i = 1; i <= m; i++)
    {
        ll l, r;
        scanf("%lld%lld", &l, &r);
        auto it1 = lower_bound(hashes.begin(), hashes.end(), hash_pair(make_pair(l, l)));
        auto it2 = upper_bound(hashes.begin(), hashes.end(), hash_pair(make_pair(r, r)));
        printf("%d\n", max(0, it2-it1));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions.count(j))
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int positions[MAXN];
vector <int> ans[MAXN];
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[MAXN];
multiset <int> s[MAXN];
void update(int pos, vector <int> a)
{
    for (int i = pos; i < MAXN; i += i & (-i))
        {
            for (int j: a)
                s[i].insert(j);
        }
}
int get(int pos, int l, int r)
{
    int ans = 0;
    for (int i = pos; i >= 1; i -= i & (-i))
    {
        auto it1 = lower_bound(tr[i].begin(), tr[i].end(), l);
        auto it2 = upper_bound(tr[i].begin(), tr[i].end(), r);
        ans += max(0, it2-it1);
    }
    return ans;
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    for (int i = 1; i <= n; i++)
        update(i, ans[i]);
        for (int i = 1; i <= n; i++)
            for (int j: s[i])
            tr[i].push_back(j);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(r, l, r) - get(l-1, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int positions[MAXN];
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[3 * MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;

void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }

int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}
int main()
{
    n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int positions[MAXN];
vector <int> ans[MAXN];
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[MAXN];
void update(int pos, vector <int> a)
{
    for (int i = pos; i < MAXN; i += i & (-i))
        tr[i] = merge(tr[i], a);
}
int get(int pos, int l, int r)
{
    int ans = 0;
    for (int i = pos; i >= 1; i -= i & (-i))
    {
        auto it1 = lower_bound(tr[i].begin(), tr[i].end(), l);
        auto it2 = upper_bound(tr[i].begin(), tr[i].end(), r);
        ans += max(0, it2-it1);
    }
    return ans;
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    for (int i = 1; i <= n; i++)
        update(i, ans[i]);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(r, l, r) - get(l-1, l, r));
    }
}


#include <bits/stdc++.h>
#pragma optimize "O3"
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int tr[MAXN];
int positions[MAXN];
void update(int pos, int val)
{
    for (pos; pos <= n; pos += pos & (-pos))
        tr[pos] += val;
}
int get(int pos)
{
    int ans = 0;
    for (pos; pos >= 1; pos -= pos & (-pos))
        ans += tr[pos];
    return ans;
}
int ans[MAXN];
vector <pair <int, int> > queries[MAXN];
vector <int> divisors[MAXN];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        queries[l].push_back(make_pair(r, i));
    }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
    if (positions[j] != 0)
        divisors[min(i, positions[j])].push_back(max(i, positions[j]));
    for (int i = n; i >= 1; i--)
    {
        for (int j: divisors[i])
            update(j, 1);
        for (auto j: queries[i])
            ans[j.second] = get(j.first);
    }
    for (int i = 1; i <= m; i++)
        printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int positions[MAXN];
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;

void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }

int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}
int main()
{
    n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
short int n, m;
short int arr[MAXN];
short int positions[MAXN];
vector <short int> merge(vector <short int> a, vector <short int> b)
{
    vector <short int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <short int> tr[4 * MAXN];
vector <short int> ans[MAXN];
void build(short int v, short int l, short int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(short int v, short int l, short int r, short int x, short int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;

void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }

int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}
int main()
{
    n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
vector <int> in[MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
    const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;
void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }
int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}

int main()
{
   n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j * j <= arr[i]; j++)
            if (arr[i] % j == 0)
        {
            if (positions[j])
                in[positions[j]].push_back(i);
            if (j != arr[i] / j)
                if (positions[arr[i] / j])
                in[positions[arr[i] / j]].push_back(i);
        }
    for (int i = 1; i <= n; i++)
        for (int j: in[i])
        ans[j].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        for (int i = 1; i * i <= arr[l]; i++)
            if (arr[l] % i == 0)
        {
            if (positions[i])
                tr[v].push_back(positions[i]);
            if (arr[l] / i != i)
                if (positions[arr[l] / i])
                tr[v].push_back(positions[arr[l] / i]);
        }
        sort(tr[v].begin(), tr[v].end());
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
long long get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return (long long)max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        {
            cin >> arr[i];
            positions[arr[i]] = i;
        }
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        cin >> l >> r;
        cout << get(1, 1, n, l, r) << endl;
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
vector <int> in[MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j * j <= arr[i]; j++)
            if (arr[i] % j == 0)
        {
            if (positions[j])
                in[positions[j]].push_back(i);
            if (j != arr[i] / j)
                if (positions[arr[i] / j])
                in[positions[arr[i] / j]].push_back(i);
        }
    for (int i = 1; i <= n; i++)
        for (int j: in[i])
        ans[j].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        for (int i = 1; i * i <= arr[l]; i++)
            if (arr[l] % i == 0)
        {
            if (positions[i])
                tr[v].push_back(positions[i]);
            if (arr[l] / i != i)
                if (positions[arr[l] / i])
                tr[v].push_back(positions[arr[l] / i]);
        }
        sort(tr[v].begin(), tr[v].end());
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
    const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;

void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }

int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}
int main()
{
   n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(arr[i]);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int positions[MAXN];
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[3 * MAXN - 1000];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;

void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }

int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}
int main()
{
    n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        for (int i = 1; i * i <= arr[l]; i++)
            if (arr[l] % i == 0)
        {
            if (positions[i])
                tr[v].push_back(positions[i]);
            if (arr[l] / i != i)
                if (positions[arr[l] / i])
                tr[v].push_back(positions[arr[l] / i]);
        }
        sort(tr[v].begin(), tr[v].end());
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;

void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }

int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}
int main()
{
    n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions.count(j))
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        for (int i = 1; i * i <= arr[l]; i++)
            if (arr[l] % i == 0)
        {
            if (positions[i])
                tr[v].push_back(positions[i]);
            if (arr[l] / i != i)
                if (positions[arr[l] / i])
                tr[v].push_back(positions[arr[l] / i]);
        }
        if (n < 100000) sort(tr[v].begin(), tr[v].end());
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    build(1, 1, n);
    if (n > 100000)
        return 0;
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int positions[MAXN];
vector <int> ans[MAXN];
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[MAXN];
set <int> s[MAXN];
void update(int pos, vector <int> a)
{
    for (int i = pos; i < MAXN; i += i & (-i))
        {
            for (int j: a)
                s[i].insert(j);
        }
}
int get(int pos, int l, int r)
{
    int ans = 0;
    for (int i = pos; i >= 1; i -= i & (-i))
    {
        auto it1 = lower_bound(tr[i].begin(), tr[i].end(), l);
        auto it2 = upper_bound(tr[i].begin(), tr[i].end(), r);
        ans += max(0, it2-it1);
    }
    return ans;
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    for (int i = 1; i <= n; i++)
        update(i, ans[i]);
        for (int i = 1; i <= n; i++)
            for (int j: s[i])
            tr[i].push_back(j);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(r, l, r) - get(l-1, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int positions[MAXN];
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[2 * MAXN + 2];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;

void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }

int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}
int main()
{
    n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int positions[MAXN];
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[2 * MAXN + MAXN / 2];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;

void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }

int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}
int main()
{
    n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        for (int i = 1; i * i <= arr[l]; i++)
            if (arr[l] % i == 0)
        {
            if (positions[i])
                tr[v].push_back(positions[i]);
            if (arr[l] / i != i)
                if (positions[arr[l] / i])
                tr[v].push_back(positions[arr[l] / i]);
        }
        sort(tr[v].begin(), tr[v].end());
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        {
            cin >> arr[i];
            positions[arr[i]] = i;
        }
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        cin >> l >> r;
        cout << get(1, 1, n, l, r) << endl;
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
int positions[MAXN];
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[2 * MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;

void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }

int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}
int main()
{
    n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = arr[i]; j < MAXN; j += arr[i])
        if (positions[j])
        ans[positions[j]].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
vector <int> in[MAXN];
vector <int> ans[MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        tr[v] = ans[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
    const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;
void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }
int read_int()
{
	ret_int = 0;
	for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
	for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
		ret_int = ret_int * 10 + buff[pos_buff] - '0';
	return ret_int;
}

int main()
{
   n = read_int();
    m = read_int();
    for (int i = 1; i <= n; i++)
        {
            arr[i] = read_int();
            positions[arr[i]] = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j * j <= n; j++)
            if (arr[i] % j == 0)
        {
            if (positions[j])
                in[positions[j]].push_back(i);
            if (j != arr[i] / j)
                if (positions[arr[i] / j] != 0)
                in[positions[arr[i] / j]].push_back(i);
        }
    for (int i = 1; i <= n; i++)
        for (int j: in[i])
        ans[j].push_back(i);
    build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        l = read_int();
        r = read_int();
        printf("%d\n", get(1, 1, n, l, r));
    }
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 200003
using namespace std;
int n, m;
int arr[MAXN];
unordered_map <int, int> positions;
vector <int> merge(vector <int> a, vector <int> b)
{
    vector <int> ans;
    int posa = 0, posb = 0;
    int sza = a.size(), szb = b.size();
    while (posa < sza && posb < szb)
    {
        if (a[posa] < b[posb])
        {
            ans.push_back(a[posa]);
            posa++;
        }
        else
        {
            ans.push_back(b[posb]);
            posb++;
        }
    }
    while (posa < sza)
    {
        ans.push_back(a[posa]);
        posa++;
    }
    while (posb < szb)
    {
        ans.push_back(b[posb]);
        posb++;
    }
    return ans;
}
vector <int> tr[4 * MAXN];
void build(int v, int l, int r)
{
    if (l == r)
    {
        for (int i = 1; i * i <= arr[l]; i++)
            if (arr[l] % i == 0)
        {
            if (positions[i])
                tr[v].push_back(positions[i]);
            if (arr[l] / i != i)
                if (positions[arr[l] / i])
                tr[v].push_back(positions[arr[l] / i]);
        }
        sort(tr[v].begin(), tr[v].end());
        return;
    }
    int mid = (l + r) >> 1;
    build(v << 1, l, mid);
    build((v << 1) + 1, mid + 1, r);
    tr[v] = merge(tr[v << 1], tr[(v << 1) + 1]);
}
int get(int v, int l, int r, int x, int y)
{
    if (l > y || r < x)
        return 0;
    if (l >= x && r <= y)
    {
        auto it1 = lower_bound(tr[v].begin(), tr[v].end(), x);
        auto it2 = upper_bound(tr[v].begin(), tr[v].end(), y);
        return max(0, it2-it1);
    }
    int mid = (l + r) >> 1;
    return get(v << 1, l, mid, x, y) + get((v << 1) + 1, mid + 1, r, x, y);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
            positions[arr[i]] = i;
        }
    build(1, 1, n);
    if (n > 100000)
        return 0;
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", get(1, 1, n, l, r));
    }
}


//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 2;
const int MAX_SEG = (int)3e6 + 3;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
int pos[MAXN], n, m;
vector<int> pc[MAXN];
pair<int, int> P[MAX_SEG];
int xs[MAX_SEG];
int ans[MAXN], fen[MAXN];
vector<pair<pair<int, int> , int> > Q;
void add(int id, int val)
{
	for (; id <= n; id += id & -id)
		fen[id] += val;
}
int get(int id)
{
	int ans = 0;
	for (; id; id -= id & -id)
		ans += fen[id];
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		pos[a] = i;
	}
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j += i)
		{
			int u = pos[i], v = pos[j];
			if(u > v)
				swap(u, v);
			pc[u].push_back(v);
		}
	for (int i = 1; i <= n; i++)
		sort(pc[i].begin(), pc[i].end());
	int t = 1;
	for (int i = 1; i <= n; i++)
	{
		for (auto u : pc[i])
			P[t++] = {i, u};
	}
	for (int i = 1; i < t; i++)
		xs[i] = P[i].first;

	for (int i = 0; i < m; i++)
	{
		int l, r;
		cin >> l >> r;
		Q.push_back({ {l, r}, i});
	}
	sort(Q.begin(), Q.end());
	int ptr = t - 1;
	for (int i = m - 1; i >= 0; i--)
	{
		while(ptr >= 1 && P[ptr].first >= Q[i].first.first)
		{
			add(P[ptr].second, 1);
			ptr--;
		}
		ans[Q[i].second] = get(Q[i].first.second);
	}
	for (int i = 0; i < m; i++)
		cout << ans[i] << "\n";
}


//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 2;
const int MAX_SEG = (int)3e6 + 3;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
int pos[MAXN];
vector<int> pc[MAXN];
pair<int, int> P[MAX_SEG];
int xs[MAX_SEG];
vector<int> seg[4 * MAX_SEG];
void build(int node, int st, int en)
{
	if(en - st < 2)
	{
		seg[node].push_back(P[st].second);
		return;
	}
	int mid = (st + en) >> 1;
	build(node << 1, st, mid);
	build(node << 1 | 1, mid, en);
	for (auto u : seg[node << 1])
		seg[node].push_back(u);
	for (auto u : seg[node << 1 | 1])
		seg[node].push_back(u);
	sort(seg[node].begin(), seg[node].end());
	return;
}
int get(int node, int st, int en, int l, int r, int val)
{
	if(st >= r || l >= en)
		return 0;
	if(l <= st && en <= r)
	{
		int st = upper_bound(seg[node].begin(), seg[node].end(), val) - seg[node].begin();
		return st;
	}
	int mid = (st + en) >> 1;
	return get(node << 1, st, mid, l, r, val) + get(node << 1 | 1, mid, en, l, r, val);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		pos[a] = i;
	}
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j += i)
		{
			int u = pos[i], v = pos[j];
			if(u > v)
				swap(u, v);
			pc[u].push_back(v);
		}
	for (int i = 1; i <= n; i++)
		sort(pc[i].begin(), pc[i].end());
	int t = 0;
	for (int i = 1; i <= n; i++)
	{
		for (auto u : pc[i])
			P[t++] = {i, u};
	}
	for (int i = 0; i < t; i++)
		xs[i] = P[i].first;
	build(1, 0, t);
	for (int i = 0; i < m; i++)
	{
		int l, r;
		cin >> l >> r;
		int st = lower_bound(xs, xs + t, l) - xs;
		cout << get(1, 0, t, st, t, r) << "\n";
	}
}