#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[10000010],mini[10000010],ara[1000005];
bool mark[10000010];
void seive()
{
    for(ll i=2; i<=10000010; i+=2)
        mark[i] = true,mini[i] = 2;
    ll lim = sqrt(10000010);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {
            mini[i] = i;
            for(ll j = i*i; j<10000010; j+=i)
            {
                if(!mark[j])
                    mini[j] = i;
                mark[j] = true;
            }
        }
    }
}

void summ(ll x)
{

    set<ll> s;
    //debug(x);
    while(x>1)
    {
        if(!mark[x])
        {
            s.insert(x);
            break;
        }
        s.insert(mini[x]);

        //debug(mini[x]);
        x/=mini[x];
    }
    for(ll x:s)
        sum[x]++;
}

int main()
{
    seive();
    ll n,a;
    cin >> n;
    for(ll i=0; i<n; i++)
        cin >> ara[i];
    for(ll i=0; i<n; i++)
        summ(ara[i]);
    for(ll i=2; i<10000005; i++)
        sum[i]+=sum[i-1];
    ll m;
    cin >> m;
    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=10000000)
        {
            cout << 0 << endl;
            continue;
        }
        b = min(b,10000000LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[10000010],mini[10000010],ara[1000005];
bool mark[10000010];
void seive()
{
    for(ll i=2; i<=1000000; i+=2)
        mark[i] = true,mini[i] = 2;
    ll lim = sqrt(10000010);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {
            mini[i] = i;
            for(ll j = i*i; j<10000010; j+=i)
            {
                if(!mark[j])
                    mini[j] = i;
                mark[j] = true;
            }
        }
    }
}

void summ(ll x)
{
    set<ll> s;
    //debug(x);
    while(x>1)
    {
        s.insert(mini[x]);
        //debug(mini[x]);
        x/=mini[x];
    }
    for(ll x:s)
        sum[x]++;
}

int main()
{
    seive();
    ll n,a;
    cin >> n;
    for(ll i=0; i<n; i++)
        cin >> ara[i];
    for(ll i=0;i<n;i++)
        summ(ara[i]);
    for(ll i=1; i<10000010; i++)
        sum[i]+=sum[i-1];
    ll m;
    cin >> m;
    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=10000000)
            {
                cout << 0 << endl;
                continue;
            }
        b = min(b,10000000LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
#define N  10000010
ll sum[N],ara[N];
bool mark[N],yo[N];
void seive()
{
    sum[2]+=ara[4];
    yo[2] = true;
    mark[4] = true;
    for(ll i=6; i<N; i+=2)
        mark[i] = true,sum[2]+=ara[i],sum[i/2]+=ara[i];
    for(ll i=3; i*i<N; i+=2)
    {
        if(!mark[i])
            yo[i]= true;
        for(ll j = i*i; j<N; j+=i)
        {
            mark[j] = true;
            if(ara[j])
            {
                sum[i]+=ara[j];
                if((i*i)!=j)
                    sum[j/i]+=ara[j];
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    ll n,a;
    cin >> n;

    for(ll i=0; i<n; i++)
        cin >> a, ara[a]++;

    seive();

    for(ll i=2; i<N-5; i++)
    {
        if(yo[i])
            sum[i]+=(sum[i-1]+ara[i]);
        else
            sum[i] = sum[i-1];
    }

    ll m;
    cin >> m;

    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=N-10)
        {
            cout << 0 << endl;
            continue;
        }
        ll p = N-10;
        b = min(b,p);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[10000010],mini[10000010],ara[1000005];
bool mark[10000010];
void seive()
{
    for(ll i=2; i<=10000010; i+=2)
        mark[i] = true,mini[i] = 2;
    ll lim = sqrt(10000010);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {
            mini[i] = i;
            for(ll j = i*i; j<10000010; j+=i)
            {
                if(!mark[j])
                    mini[j] = i;
                mark[j] = true;
            }
        }
    }
}

void summ(ll x)
{

    set<ll> s;
    //debug(x);
    while(x>1)
    {
        if(!mark[x])
        {
            s.insert(x);
            break;
        }
        s.insert(mini[x]);

        //debug(mini[x]);
        x/=mini[x];
    }
    for(ll x:s)
        sum[x]++;
}

int main()
{
    seive();
    ll n,a;
    cin >> n;
    for(ll i=0; i<n; i++)
        cin >> ara[i];
    for(ll i=0; i<n; i++)
        summ(ara[i]);
    for(ll i=2; i<5000005; i++)
        sum[i]+=sum[i-1];
    ll m;
    cin >> m;
    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=5000005)
        {
            cout << 0 << endl;
            continue;
        }
        b = min(b,5000005LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
int sum[10000010],mini[10000010];
bool mark[10000010];
void seive()
{
    for(int i=2; i<=1000000; i+=2)
        mark[i] = true,mini[i] = 2;
    int lim = sqrt(10000010);
    for(int i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {
            mini[i] = i;
            for(int j = i*i; j<10000010; j+=i)
            {
                if(!mark[j])
                    mini[j] = i;
                mark[j] = true;
            }
        }
    }
}

void summ(int x)
{
    set<int> s;
    //debug(x);
    while(x>1)
    {
        s.insert(mini[x]);
        //debug(mini[x]);
        x/=mini[x];
    }
    for(int x:s)
        sum[x]++;
}

int main()
{
    seive();
    int n,a;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> a,summ(a);
    for(int i=1; i<10000010; i++)
        sum[i]+=sum[i-1];
    int m;
    cin >> m;
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin >> a >> b;
        b = min(b,10000000);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cout << #x << " " << x << endl
#define fast ios_base::sync_with_stdio(false);
#define N 10000005LL
ll counter[N+5],ans[N+5];
bool is[N+5];
void work()
{
    for(ll i=2; i<N; i++)
    {
        ans[i] = ans[i-1];
        if(!is[i])
            for(ll j=i; j<N; j+=i)
            {
                ans[i]+=counter[j];
                is[j] = true;
            }
    }
}
int main()
{
    fast
    ll n,a,b;
    cin >> n;
    for(ll i=0; i<n; i++)
        cin >> a, counter[a]++;
    work();
    ll m;
    cin >> m;
    for(ll i=0; i<m; i++)
    {
        cin >> a >> b;
        if(a>=N)
        {
            cout << 0 << endl;
            continue;
        }
        b = min(b,N-1LL);
        cout << ans[b]-ans[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[10000010],ara[10000010];
bool mark[10000010],yo[10000010];
void seive()
{
    for(ll i=2; i<10000010; i+=2)
        mark[i] = true,sum[2]+=ara[i],sum[i/2]+=ara[i];//,debug(ara[i]);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {

            for(ll j = i*i; j<10000010; j+=i)
            {
                mark[j] = true;
                if(yo[j]){
                sum[i]+=ara[j];
                sum[j/i]+=ara[j];
                }
            }
        }
    }
}

//void summ(ll x)
//{
//
//    set<ll> s;
//    //debug(x);
//    while(x>1)
//    {
//        if(!mark[x])
//        {
//            s.insert(x);
//            break;
//        }
//        s.insert(mini[x]);
//
//        //debug(mini[x]);
//        x/=mini[x];
//    }
//    for(ll x:s)
//        sum[x]++;
//}

int main()
{

    ll n,a;
    cin >> n;

    for(ll i=0; i<n; i++)
        cin >> a, ara[a]++,yo[a]=true;

    seive();

//    for(ll i=0; i<n; i++)
//        summ(ara[i]);

    for(ll i=3; i<10000005; i++)
    {
        //debug(sum[i]);
        if(!mark[i])
            sum[i]+=(sum[i-1]+ara[i]);
        else
            sum[i] = sum[i-1];
    }

    ll m;

    cin >> m;

    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=10000005)
        {
            cout << 0 << endl;
            continue;
        }
        b = min(b,10000005LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[5000010],mini[10000010],ara[1000005];
bool mark[10000010];
void seive()
{
    for(ll i=2; i<=1000000; i+=2)
        mark[i] = true,mini[i] = 2;
    ll lim = sqrt(10000010);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {
            mini[i] = i;
            for(ll j = i*i; j<10000010; j+=i)
            {
                if(!mark[j])
                    mini[j] = i;
                mark[j] = true;
            }
        }
    }
}

void summ(ll x)
{
    if(!mark[x]){
        sum[x]++;
        return;
        }
    set<ll> s;
    //debug(x);
    while(x>1)
    {
        s.insert(mini[x]);
        //debug(mini[x]);
        x/=mini[x];
    }
    for(ll x:s)
        sum[x]++;
}

int main()
{
    seive();
    ll n,a;
    cin >> n;
    for(ll i=0; i<n; i++)
        cin >> ara[i];
    for(ll i=0;i<n;i++)
        summ(ara[i]);
    for(ll i=2; i<5000005; i++)
        sum[i]+=sum[i-1];
    ll m;
    cin >> m;
    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=5000005)
            {
                cout << 0 << endl;
                continue;
            }
        b = min(b,5000005LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[10000010],ara[10000010];
bool mark[10000010],yo[10000010];
void seive()
{
    for(ll i=2; i<10000010; i+=2)
        mark[i] = true,sum[2]+=ara[i],sum[i/2]+=ara[i];//,debug(ara[i]);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {
            sum[i]+=ara[i];
            for(ll j = i*i; j<10000010; j+=i)
            {
                mark[j] = true;
                if(yo[j]){
                sum[i]+=ara[j];
                sum[j/i]+=ara[j];
                }
            }
        }
    }
}

//void summ(ll x)
//{
//
//    set<ll> s;
//    //debug(x);
//    while(x>1)
//    {
//        if(!mark[x])
//        {
//            s.insert(x);
//            break;
//        }
//        s.insert(mini[x]);
//
//        //debug(mini[x]);
//        x/=mini[x];
//    }
//    for(ll x:s)
//        sum[x]++;
//}

int main()
{

    ll n,a;
    cin >> n;

    for(ll i=0; i<n; i++)
        cin >> a, ara[a]++,yo[a]=true;

    seive();

//    for(ll i=0; i<n; i++)
//        summ(ara[i]);

    for(ll i=3; i<10000005; i++)
    {
        //debug(sum[i]);
        if(!mark[i])
            sum[i]+=sum[i-1];
        else
            sum[i] = sum[i-1];
    }

    ll m;

    cin >> m;

    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=10000005)
        {
            cout << 0 << endl;
            continue;
        }
        b = min(b,10000005LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[10000010],ara[10000010];
bool mark[10000010],yo[10000010];
void seive()
{
    sum[2]+=ara[4];
    mark[4] = true;
    for(ll i=6; i<10000010; i+=2)
        mark[i] = true,sum[2]+=ara[i],sum[i/2]+=ara[i];//,debug(ara[i]);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {

            for(ll j = i*i; j<10000010; j+=i)
            {
                mark[j] = true;
                if(yo[j]){
                sum[i]+=ara[j];
                if((i*i)!=j)
                sum[j/i]+=ara[j];
                }
            }
        }
    }
}

//void summ(ll x)
//{
//
//    set<ll> s;
//    //debug(x);
//    while(x>1)
//    {
//        if(!mark[x])
//        {
//            s.insert(x);
//            break;
//        }
//        s.insert(mini[x]);
//
//        //debug(mini[x]);
//        x/=mini[x];
//    }
//    for(ll x:s)
//        sum[x]++;
//}

int main()
{

    ll n,a;
    cin >> n;

    for(ll i=0; i<n; i++)
        cin >> a, ara[a]++,yo[a]=true;

    seive();

//    for(ll i=0; i<n; i++)
//        summ(ara[i]);

    for(ll i=2; i<10000005; i++)
    {
        //debug(sum[i]);
        if(!mark[i])
            sum[i]+=(sum[i-1]+ara[i]);
        else
            sum[i] = sum[i-1];
    }

    ll m;

    cin >> m;

    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=10000000)
        {
            cout << 0 << endl;
            continue;
        }
        b = min(b,10000000LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[10000010],mini[10000010],ara[1000005];
bool mark[10000010];
void seive()
{
    for(ll i=2; i<=10000010; i+=2)
        mark[i] = true,mini[i] = 2;
    ll lim = sqrt(10000010);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {
            mini[i] = i;
            for(ll j = i*i; j<10000010; j+=i)
            {
                if(!mark[j])
                    mini[j] = i;
                mark[j] = true;
            }
        }
    }
}

void summ(ll x)
{

    set<ll> s;
    //debug(x);
    while(x>1)
    {
        if(!mark[x])
        {
            s.insert(x);
            break;
        }
        s.insert(mini[x]);

        //debug(mini[x]);
        x/=mini[x];
    }
    for(ll x:s)
        sum[x]++;
}

int main()
{
        ios_base::sync_with_stdio(false);

    seive();
    ll n,a;
    cin >> n;
    for(ll i=0; i<n; i++)
        cin >> ara[i];
    for(ll i=0; i<n; i++)
        summ(ara[i]);
    for(ll i=2; i<10000005; i++)
        sum[i]+=sum[i-1];
    ll m;
    cin >> m;
    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=10000000)
        {
            cout << 0 << endl;
            continue;
        }
        b = min(b,10000000LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[10000010],mini[10000010],ara[1000005];
bool mark[10000010];
void seive()
{
    for(ll i=2; i<=1000000; i+=2)
        mark[i] = true,mini[i] = 2;
    ll lim = sqrt(10000010);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {
            mini[i] = i;
            for(ll j = i*i; j<10000010; j+=i)
            {
                if(!mark[j])
                    mini[j] = i;
                mark[j] = true;
            }
        }
    }
}

void summ(ll x)
{
    set<ll> s;
    //debug(x);
    while(x>1)
    {
        s.insert(mini[x]);
        //debug(mini[x]);
        x/=mini[x];
    }
    for(ll x:s)
        sum[x]++;
}

int main()
{
    seive();
    ll n,a;
    cin >> n;
    for(ll i=0; i<n; i++)
        cin >> ara[i];
    for(ll i=0;i<n;i++)
        summ(ara[i]);
    for(ll i=2; i<10000000; i++)
        sum[i]+=sum[i-1];
    ll m;
    cin >> m;
    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=5000005)
            {
                cout << 0 << endl;
                continue;
            }
        b = min(b,5000005LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
ll sum[10000010],ara[10000010];
bool mark[10000010],yo[10000010];
void seive()
{
    sum[2]+=ara[4];
    mark[4] = true;
    for(ll i=6; i<10000010; i+=2)
        mark[i] = true,sum[2]+=ara[i],sum[i/2]+=ara[i];//,debug(ara[i]);
    for(ll i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {

            for(ll j = i*i; j<10000010; j+=i)
            {
                mark[j] = true;
                if(yo[j]){
                sum[i]+=ara[j];
                if((i*i)!=j)
                sum[j/i]+=ara[j];
                }
            }
        }
    }
}

//void summ(ll x)
//{
//
//    set<ll> s;
//    //debug(x);
//    while(x>1)
//    {
//        if(!mark[x])
//        {
//            s.insert(x);
//            break;
//        }
//        s.insert(mini[x]);
//
//        //debug(mini[x]);
//        x/=mini[x];
//    }
//    for(ll x:s)
//        sum[x]++;
//}

int main()
{

    ll n,a;
    cin >> n;

    for(ll i=0; i<n; i++)
        cin >> a, ara[a]++,yo[a]=true;

    seive();

//    for(ll i=0; i<n; i++)
//        summ(ara[i]);

    for(ll i=2; i<10000005; i++)
    {
        //debug(sum[i]);
        if(!mark[i])
            sum[i]+=(sum[i-1]+ara[i]);
        else
            sum[i] = sum[i-1];
    }

    ll m;

    cin >> m;

    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=10000005)
        {
            cout << 0 << endl;
            continue;
        }
        b = min(b,10000005LL);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cout << #x << " " << x << endl
#define fast ios_base::sync_with_stdio(false);

#define N 10000005LL

ll count[N+5],ans[N+5];
bool is[N+5];

void work()
{
    for(ll i=2; i<N; i++)
    {
        ans[i] = ans[i-1];
        if(!is[i])
            for(ll j=i; j<N; j+=i)
            {
                ans[i]+=count[j];
                is[j] = true;
            }
    }
}

int main()
{
    fast
    ll n,a,b;
    cin >> n;
    for(ll i=0; i<n; i++)
        cin >> a, count[a]++;

    work();
    //cout << "Ready";

    ll m;
    cin >> m;
    for(ll i=0; i<m; i++)
    {
        cin >> a >> b;
        if(a>=N)
        {
            cout << 0 << endl;
            continue;
        }
        b = min(b,N-1LL);
        cout << ans[b]-ans[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
#define ll long long
#define N  10000010
ll sum[N],ara[N];
bool mark[N],yo[N];
void seive()
{
    sum[2]+=ara[4];
    mark[4] = true;
    for(ll i=6; i<N; i+=2)
        mark[i] = true,sum[2]+=ara[i],sum[i/2]+=ara[i];
    for(ll i=3; i*i<N; i+=2)
    {
        if(!mark[i])
        {

            for(ll j = i*i; j<N; j+=i)
            {
                mark[j] = true;
                if(yo[j])
                {
                    sum[i]+=ara[j];
                    if((i*i)!=j)
                        sum[j/i]+=ara[j];
                }
            }
        }
    }
}
int main()
{

    ll n,a;
    cin >> n;

    for(ll i=0; i<n; i++)
        cin >> a, ara[a]++,yo[a]=true;

    seive();

    for(ll i=2; i<N-5; i++)
    {
        if(!mark[i])
            sum[i]+=(sum[i-1]+ara[i]);
        else
            sum[i] = sum[i-1];
    }

    ll m;
    cin >> m;

    for(ll i=0; i<m; i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a>=N-10)
        {
            cout << 0 << endl;
            continue;
        }
        ll p = N-10;
        b = min(b,p);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << endl
int sum[10000010],mini[10000010],ara[1000005];
bool mark[10000010];
void seive()
{
    for(int i=2; i<=1000000; i+=2)
        mark[i] = true,mini[i] = 2;
    int lim = sqrt(10000010);
    for(int i=3; i*i<10000010; i+=2)
    {
        if(!mark[i])
        {
            mini[i] = i;
            for(int j = i*i; j<10000010; j+=i)
            {
                if(!mark[j])
                    mini[j] = i;
                mark[j] = true;
            }
        }
    }
}

void summ(int x)
{
    set<int> s;
    //debug(x);
    while(x>1)
    {
        s.insert(mini[x]);
        //debug(mini[x]);
        x/=mini[x];
    }
    for(int x:s)
        sum[x]++;
}

int main()
{
    seive();
    int n,a;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> ara[i];
    for(int i=0;i<n;i++)
        summ(ara[i]);
    for(int i=1; i<10000010; i++)
        sum[i]+=sum[i-1];
    int m;
    cin >> m;
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin >> a >> b;
        if(a>=10000000)
            {
                cout << 0 << endl;
                continue;
            }
        b = min(b,10000000);
        cout << sum[b]-sum[a-1] << endl;
    }
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll x;
        ll cnt[10000001]={};
        ll dp[10000001]={};
        rep(i,0,n)
        {
            cin>>x;
            cnt[x]++;
        }
        ll prime[10000001]={};
        prime[0]=prime[1]=1;
        rep(i,2,10000001)
        {
            if( prime[i]==0 )
            {
                for( ll j=i;j<10000001;j+=i )
                {
                    prime[j]=1;
                    dp[i]+=cnt[j];
                }
            }
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,1,10000001 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
            //    cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;
            l=min(l,(ll)1e7);
		    r=min(r,(ll)1e7);
            ans=dp[r]-dp[l-1];
            cout<<ans<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll a[n];
        //map<ll,ll> mp;
        ll dp[10000000]={};
        rep(i,0,n)
        {
            cin>>a[i];
            primeFactors( a[i] , dp );
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,2,10000000 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
                //cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;

            //cout<<"size.."<<mp.size();
            // for( auto x : mp )
            // {
            //     //cout<<x.first<<' '<<x.second<<'\n';
            //     if( x.first >= l )
            //     {
            //         if( x.first<=r )
            //         {
            //             ans+=x.second;
            //         }
            //         else
            //         break;
            //     }
            // }
            //cout<<dp[l]<<' '<<dp[r]<<'\n';
            l=min(l,(ll)1e7);
		    r=min(r,(ll)1e7);
            ans=dp[r]-dp[l-1];
            cout<<ans<<'\n';
            //cout<<dp[min((ll)10000000+9,r)]-dp[l-1]<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll a[n];
        //map<ll,ll> mp;
        ll dp[10000001]={};
        rep(i,0,n)
        {
            cin>>a[i];
            primeFactors( a[i] , dp );
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,2,10000001 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
                //cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;

            //cout<<"size.."<<mp.size();
            // for( auto x : mp )
            // {
            //     //cout<<x.first<<' '<<x.second<<'\n';
            //     if( x.first >= l )
            //     {
            //         if( x.first<=r )
            //         {
            //             ans+=x.second;
            //         }
            //         else
            //         break;
            //     }
            // }
            //cout<<dp[l]<<' '<<dp[r]<<'\n';
            l=min(l,(ll)1e7);
		    r=min(r,(ll)1e7);
            ans=dp[r]-dp[l-1];
            cout<<ans<<'\n';
            //cout<<dp[min((ll)10000000+9,r)]-dp[l-1]<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll x;
        ll cnt[10000001]={};
        ll dp[10000001]={};
        rep(i,0,n)
        {
            cin>>x;
            cnt[x]++;
        }
        ll prime[101]={};
        prime[0]=prime[1]=1;
        rep(i,2,10000001)
        {
            dp[i]=dp[i-1];
            if( prime[i]==0 )
            {
                for( ll j=i;j<101;j+=i )
                {
                    prime[j]=1;
                    dp[i]+=cnt[j];
                }
            }
        }
        ll m;
        cin>>m;
        ll l,r;
        // rep(i,1,10000001 )
        // {
        //     //if( dp[i]!=0 )
        //     dp[i]=dp[i-1]+dp[i];
        //     {
        //     //    cout<<i<<' '<<dp[i]<<'\n';
        //     }
        //}
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;
            l=min(l,(ll)1e7);
		    r=min(r,(ll)1e7);
            ans=dp[r]-dp[l-1];
            cout<<ans<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , map<ll,ll> &mp )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            mp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                mp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       mp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll a[n];
        map<ll,ll> mp;
        rep(i,0,n)
        {
            cin>>a[i];
            primeFactors( a[i] , mp );
        }
        ll m;
        cin>>m;
        ll l,r;
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;
            //cout<<"size.."<<mp.size();
            for( auto x : mp )
            {
                //cout<<x.first<<' '<<x.second<<'\n';
                if( x.first >= l )
                {
                    if( x.first<=r )
                    {
                        ans+=x.second;
                    }
                    else
                    break;
                }
            }
              cout<<ans<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll a[n];
        //map<ll,ll> mp;
        ll dp[1000000+10]={};
        rep(i,0,n)
        {
            cin>>a[i];
            primeFactors( a[i] , dp );
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,2,1000000+10 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
                //cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;

            //cout<<"size.."<<mp.size();
            // for( auto x : mp )
            // {
            //     //cout<<x.first<<' '<<x.second<<'\n';
            //     if( x.first >= l )
            //     {
            //         if( x.first<=r )
            //         {
            //             ans+=x.second;
            //         }
            //         else
            //         break;
            //     }
            // }
            //cout<<dp[l]<<' '<<dp[r]<<'\n';
            if( l>0 )
            cout<<dp[r]-dp[l-1]<<'\n';
            else
            cout<<dp[r]<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll a[n];
        //map<ll,ll> mp;
        ll dp[1000000+10]={};
        rep(i,0,n)
        {
            cin>>a[i];
            primeFactors( a[i] , dp );
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,2,1000000+10 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
                //cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;

            //cout<<"size.."<<mp.size();
            // for( auto x : mp )
            // {
            //     //cout<<x.first<<' '<<x.second<<'\n';
            //     if( x.first >= l )
            //     {
            //         if( x.first<=r )
            //         {
            //             ans+=x.second;
            //         }
            //         else
            //         break;
            //     }
            // }
            //cout<<dp[l]<<' '<<dp[r]<<'\n';
            if( l>0 )
            cout<<dp[min((ll)1000000+9,r)]-dp[l-1]<<'\n';
            else
            cout<<dp[min((ll)1000000+9,r)]<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll a[n];
        //map<ll,ll> mp;
        ll dp[1000000+10]={};
        rep(i,0,n)
        {
            cin>>a[i];
            primeFactors( a[i] , dp );
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,2,1000000+10 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
                //cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;

            //cout<<"size.."<<mp.size();
            // for( auto x : mp )
            // {
            //     //cout<<x.first<<' '<<x.second<<'\n';
            //     if( x.first >= l )
            //     {
            //         if( x.first<=r )
            //         {
            //             ans+=x.second;
            //         }
            //         else
            //         break;
            //     }
            // }
            //cout<<dp[l]<<' '<<dp[r]<<'\n';
            cout<<dp[r]-dp[l-1]<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll x;
        ll cnt[10000001]={};
        ll dp[10000001]={};
        rep(i,0,n)
        {
            cin>>x;
            cnt[x]++;
        }
        ll prime[10000001]={};
        prime[0]=prime[1]=1;
        rep(i,2,10000001)
        {
            if( prime[i]==0 )
            {
                for( ll j=i;j<101;j+=i )
                {
                    prime[j]=1;
                    dp[i]+=cnt[j];
                }
            }
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,1,10000001 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
            //    cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;
            l=min(l,(ll)1e7);
		    r=min(r,(ll)1e7);
            ans=dp[r]-dp[l-1];
            cout<<ans<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll x;
        ll cnt[10000001]={};
        ll dp[10000001]={};
        rep(i,0,n)
        {
            cin>>x;
            cnt[x]++;
        }
        ll prime[101]={};
        prime[0]=prime[1]=1;
        rep(i,2,10000001)
        {
            if( prime[i]==0 )
            {
                for( ll j=i;j<101;j+=i )
                {
                    prime[j]=1;
                    dp[i]+=cnt[j];
                }
            }
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,1,10000001 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
            //    cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;

            l=min(l,(ll)1e7);
		    r=min(r,(ll)1e7);
            ans=dp[r]-dp[l-1];
            cout<<ans<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll a[n];
        //map<ll,ll> mp;
        ll dp[10000000+10]={};
        rep(i,0,n)
        {
            cin>>a[i];
            primeFactors( a[i] , dp );
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,2,10000000+10 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
                //cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;

            //cout<<"size.."<<mp.size();
            // for( auto x : mp )
            // {
            //     //cout<<x.first<<' '<<x.second<<'\n';
            //     if( x.first >= l )
            //     {
            //         if( x.first<=r )
            //         {
            //             ans+=x.second;
            //         }
            //         else
            //         break;
            //     }
            // }
            //cout<<dp[l]<<' '<<dp[r]<<'\n';
            if( l>0 )
            cout<<dp[min((ll)10000000+9,r)]-dp[l-1]<<'\n';
            else
            cout<<dp[min((ll)10000000+9,r)]<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , ll dp[] )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            dp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                dp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       dp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll a[n];
        //map<ll,ll> mp;
        ll dp[1000000+10]={};
        rep(i,0,n)
        {
            cin>>a[i];
            primeFactors( a[i] , dp );
        }
        ll m;
        cin>>m;
        ll l,r;
        rep(i,2,1000000+10 )
        {
            //if( dp[i]!=0 )
            dp[i]=dp[i-1]+dp[i];
            {
                //cout<<i<<' '<<dp[i]<<'\n';
            }
        }
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;

            //cout<<"size.."<<mp.size();
            // for( auto x : mp )
            // {
            //     //cout<<x.first<<' '<<x.second<<'\n';
            //     if( x.first >= l )
            //     {
            //         if( x.first<=r )
            //         {
            //             ans+=x.second;
            //         }
            //         else
            //         break;
            //     }
            // }
            //cout<<dp[l]<<' '<<dp[r]<<'\n';
            if( l>0 )
            cout<<dp[min((ll)1000000+10,r)]-dp[l-1]<<'\n';
            else
            cout<<dp[min((ll)1000000+10,r]<<'\n';
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
//#define rem 1000000007
#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
void primeFactors(ll n , map<ll,ll> &mp )
{
    // Print the number of 2s that divide n
    ll x=0;
    while (n % 2 == 0)
    {
        if( !x )
        {
            mp[2]++;
            x=1;
        }
        //cout << 2 << " ";
        n = n/2;
    }
    x=0;
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            if( !x )
            {
                mp[i]++;
                x=1;
            }
            //cout << i << " ";
            n = n/i;
        }
        x=0;
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
       mp[n]++;// cout << n << " ";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll a[n];
        map<ll,ll> mp;
        rep(i,0,n)
        {
            cin>>a[i];
            primeFactors( a[i] , mp );
        }
        ll m;
        cin>>m;
        ll l,r;
        while( m-- )
        {
            cin>>l>>r;
            ll ans=0;
            //cout<<"size.."<<mp.size();
            for( auto x : mp )
            {
                //cout<<x.first<<' '<<x.second<<'\n';
                if( x.first >= l )
                {
                    if( x.first<=r )
                    {
                        ans+=x.second;
                    }
                    else
                    break;
                }
            }
            cout<<ans<<'\n';
        }
    }
 }


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax ;
int a[3000003];
map <int,int> val;
set <int> st;
set <int>::iterator it;
int main(){
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        while(a[i] > 1){
            for(int j = 2 ; j <= a[i] ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; break;}
            }
        }
        for(it = st.begin() ; it!=st.end() ; it++){
          if(*it > cmax) break;
          val[*it]++;
             }
             st.clear();
    }
    for(int i = 1 ; i <= cmax ; i++){
        val[i] += val[i-1];
    }
    cin>>m;
    for(int i = 0; i < m ; i++) {
        cin>>l>>r;
        if(l < cmax){
       if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
       else {cout<<val[r]-val[l-1]<<endl;}
        }
        else cout<<0<<endl;
}
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int a[1000000] , b[1000000] , n , r , l , c , m ,cnt , x ,sum , cmax;
int primes[3000003];
map <int ,int> val;
int main(){

        for(int i = 2 ; i < sqrt(10000) ; i++){
            for(int j = i ; j <= 10000/i ; j++ ){
                a[i*j] = 1;
            }
        }
    // for(int i = 2 ; i < 10000 ; i++){
    //     if(a[i] != 1){
    //         for(int j = i ; j < 1000000 ; j += i){
    //             val[j]++;
    //         }
    //     }
    // }
    cin>>n;
    for(int i = 0 ; i <  n ; i++){
        cin>>b[i]; cmax = max(b[i],cmax);
    }
    cin>>m;
    for(int k = 0 ; k < m ; k++){
        cin>>l>>r;
    val.clear();
     for(int i = l ; i <= min(cmax,r) ; i++){
        if(a[i] != 1){
            for(int j = i ; j <= cmax ; j += i){
                val[j]++;
            }
        }
    }
    for(int i = 0 ; i < n ; i++) sum+=val[b[i]];
    cout<<sum<<endl;
    sum = 0;
    }

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt , b , f;
int val[30000003];
int primes[30000003];
int main(){
    for(int i = 2 ; i <= 10000000 ; i++){
        if(primes[i] == 0){
            primes[i] = i;
        for(int j = (i<<1) ; j <= 10000000 ; j+=i)
        if(primes[j] == 0) primes[j] = i;
        }
    }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
         scanf("%d",&b); cmax = max(b,cmax);
        while(b > 1){
            val[primes[b]]++;
            f = primes[b];
            while((b % f) == 0){
                b /= f;
            }

        }
    }

    for(int i = 1 ; i <= cmax ; i++){
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l <= cmax){
        if(r > cmax) {printf("%d\n",val[cmax]-val[r-1]);}
        else {printf("%d\n",val[r]-val[l-1]);}
            }
            else printf("%d\n",0);
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int a[1000000] , b[1000000] , n , r , l , c , m ,cnt , x ,sum , cmax , findex, sindex;
int val[3000003];
int primes[3000003];
bool flag = 0;
int main(){
        //*here i get prime numbers
        for(int i = 2 ; i < sqrt(1000) ; i++){
            for(int j = i ; j <= 1000/i ; j++ ){
                a[i*j] = 1;
            }
        }
        for(int i = 2 ; i <= 1000 ; i++){
            if(a[i]!=1) primes[cnt++] = i;
        }
        //*here i finished dragging them into array
         cin>>n;
    for(int i = 0 ; i <  n ; i++){
        cin>>b[i]; cmax = max(b[i],cmax); //biggest number input
    }

    cin>>m;
    for(int k = 0 ; k < m ; k++){
        cin>>l>>r;
         for(int j = 0 ; j < n ; j ++)  val[b[j]] = 0;
         findex = -1; sindex = -1;
         for(int i = 0 ; i < cnt ; i++) {
             if(primes[i] > r) break;
             if(primes[i] >= l && !flag ) { findex = i; flag = 1; }
             if(primes[i] <= r) sindex = i;
         }

         flag = 0;

   if(findex!=-1 && sindex!=-1){
        for(int i = findex ; i <= sindex ; i++){
       if(primes[i] > r) break;
       if(primes[i] >= l){
          for(int j = primes[i] ; j <= cmax ; j+=primes[i]){
                 val[j]++;
          }
       }
     }
    for(int i = 0 ; i < n ; i++) sum+=val[b[i]];
     cout<<sum<<endl;
   }
    else cout<<0<<endl;
     sum = 0;
    }

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt , b , f;
int val[30000003];
int primes[30000003];
int main(){
    for(int i = 2 ; i <= 10000000 ; i++){
        if(primes[i] == 0){
            primes[i] = i;
        for(int j = i*2 ; j <= 10000000 ; j+=i)
        if(primes[j] == 0) primes[j] = i;
        }
    }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>b; cmax = max(b,cmax);
        while(b > 1){
            val[primes[b]]++;
            f = primes[b];
            while((b % f) == 0){
                b /= f;
            }

        }
    }

    for(int i = 1 ; i <= cmax ; i++){
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l <= cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
long long n , m , l , r ,cmax , num ;
long long  a[300000003];
long long val[30000003];
set <long long> st;
set <long long>::iterator it;
bool wasthere = 0;
int main(){
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        num = a[i];
        while(a[i] > 1){
            for(int j = 2 ; j <= a[i] ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; wasthere = 1; break;}
            }
            if(!wasthere) { st.insert(num); break; }
        }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++;
             }
             st.clear();
    }

    for(int i = 1 ; i <= cmax ; i++){
      //cout<<val[i]<<" ";
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt;
int a[30000003];
int val[30000003];
int re_primes[30000003];
int primes[30000003];
set <int> st;
set <int>::iterator it;
bool wasthere = 0;
int main(){
    // for(int i = 2 ; i <= 5000 ; i++){
    //     for(int j = i ; j < 5000/i ; j++){
    //         re_primes[i*j] = 1;
    //     }
    // }
    // for(int i = 2 ; i <= 5000 ; i++){
    //     if(re_primes[i]!=1) {primes[cnt++] = i;}
    // }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        num = a[i] / 2;
        while(a[i] > 0){
            for(int j = 2 ; j <= num ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; wasthere = 1; break; }
            }
        }
            if(!wasthere) { st.insert(a[i]); }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++;
             }
             st.clear();
             wasthere = 0;
    }

    for(int i = 1 ; i <= cmax ; i++){
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num ;
int a[30000003];
int val[30000003];
set <int> st;
set <int>::iterator it;
bool wasthere = 0;
int main(){
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        num = a[i] / 2;
            for(int j = 2 ; j <= num ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; wasthere = 1; }
            }
            if(!wasthere) { st.insert(a[i]); }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++;
             }
             st.clear();
             wasthere = 0;
    }

    for(int i = 1 ; i <= cmax ; i++){
      //cout<<val[i]<<" ";
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt;
int a[30000003];
int val[30000003];
int re_primes[30000003];
int primes[30000003];
set <int> st;
set <int>::iterator it;
bool wasthere = 0;
int main(){
    for(int i = 2 ; i <= 5000 ; i++){
        for(int j = i ; j < 5000/i ; j++){
            re_primes[i*j] = 1;
        }
    }
    for(int i = 2 ; i <= 5000 ; i++){
        if(re_primes[i]!=1) {primes[cnt++] = i;}
    }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        num = a[i] / 2;
            for(int j = 0 ; primes[j] <= num ; j++){
                if(primes[j]>num) break;
                if(a[i]%primes[j]==0) {st.insert(primes[j]); a[i]/=primes[j]; wasthere = 1; }
            }
            if(!wasthere) { st.insert(a[i]); }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++;
             }
             st.clear();
             wasthere = 0;
    }

    for(int i = 1 ; i <= cmax ; i++){
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt;
int a[30000003];
int val[30000003];
int re_primes[30000003];
int primes[30000003];
set <int> st;
set <int>::iterator it;
bool wasthere = 0;
int main(){
    for(int i = 2 ; i <= 5000000 ; i++){
        for(int j = i ; j < 5000000/i ; j++){
            re_primes[i*j] = 1;
        }
    }
    for(int i = 2 ; i <= 5000000 ; i++){
        if(re_primes[i]!=1) {primes[cnt++] = i;}
    }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        num = a[i] / 2;
            for(int j = 0 ; j <= cnt ; j++){
                if(primes[j] > a[i]) break;
                if(a[i]%primes[j]==0) {st.insert(primes[j]); a[i]/=primes[j]; wasthere = 1; }
            }
            if(!wasthere) { st.insert(a[i]); }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++;
             }
             st.clear();
             wasthere = 0;
    }

    for(int i = 1 ; i <= cmax ; i++){
      //cout<<val[i]<<" ";
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax ;
int a[3000003];
int val[3000003];
set <int> st;
set <int>::iterator it;
int main(){
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        while(a[i] > 1){
            for(int j = 2 ; j <= a[i] ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; break;}
            }
        }
        for(it = st.begin() ; it!=st.end() ; it++){
          if(*it > cmax) break;
          val[*it]++;
             }
             st.clear();
    }
    for(int i = 1 ; i <= cmax ; i++){
        val[i] += val[i-1];
    }
    cin>>m;
    for(int i = 0; i < m ; i++) {
        cin>>l>>r;
        if(l < cmax){
       if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
       else {cout<<val[r]-val[l-1]<<endl;}
        }
        else cout<<0<<endl;
}
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int a[1000000] , b[1000000] , n , r , l , c , m ,cnt , x ,sum , cmax;
int val[3000003];
int primes[3000003];
int main(){

        for(int i = 2 ; i < sqrt(10000) ; i++){
            for(int j = i ; j <= 10000/i ; j++ ){
                a[i*j] = 1;
            }
        }
        for(int i = 2 ; i <= 10000 ; i++){
            if(a[i]!=1) primes[cnt++] = i;
        }
         cin>>n;
    for(int i = 0 ; i <  n ; i++){
        cin>>b[i]; cmax = max(b[i],cmax);
    }

    cin>>m;
    for(int k = 0 ; k < m ; k++){
        cin>>l>>r;
         for(int j = 0 ; j < n ; j ++)  val[b[j]] = 0;
    for(int i = 0 ; i < cnt ; i++){
       if(primes[i] > r) break;
       if(primes[i] >= l){
          for(int j = primes[i] ; j <= cmax ; j+=primes[i]){
                 val[j]++;
          }
       }
     }
    for(int i = 0 ; i < n ; i++) sum+=val[b[i]];
    cout<<sum<<endl;
    sum = 0;
    }

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num ;
int a[30000003];
int val[30000003];
set <int> st;
set <int>::iterator it;
bool wasthere = 0;
int main(){
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        num = a[i] / 2;
        while(a[i] > 1){
            for(int j = 2 ; j <= num ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; num = a[i]; wasthere = 1; break;}
            }
            if(!wasthere) { st.insert(num); break; }
        }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++;
             }
             st.clear();
    }

    for(int i = 1 ; i <= cmax ; i++){
      //cout<<val[i]<<" ";
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt;
int a[30000003];
int val[30000003];
int re_primes[30000003];
int primes[30000003];
set <int> st;
set <int>::iterator it;
bool wasthere = 0;
int main(){
    for(int i = 2 ; i <= 5000 ; i++){
        for(int j = i ; j < 5000/i ; j++){
            re_primes[i*j] = 1;
        }
    }
    for(int i = 2 ; i <= 5000 ; i++){
        if(re_primes[i]!=1) {primes[cnt++] = i;}
    }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        num = a[i] / 2;
            for(int j = 0 ; primes[j] <= num ; j++){
                if(a[i]%primes[j]==0) {st.insert(primes[j]); a[i]/=primes[j]; wasthere = 1; }
            }
            if(!wasthere) { st.insert(a[i]); }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++;
             }
             st.clear();
             wasthere = 0;
    }

    for(int i = 1 ; i <= cmax ; i++){
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt;
int a[30000003];
int val[30000003];
int re_primes[30000003];
int primes[30000003];
set <int> st;
set <int>::iterator it;
bool wasthere = 0;
int main(){
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        num = a[i] / 2;
        while(a[i] > 1){
            for(int j = 2 ; j <= num ; j++){
                if(a[i]%j==0) { while(a[i]%j==0) {a[i]/=j;} val[j]++; wasthere = 1; num/=2; break; }
            }
            if(!wasthere) {val[a[i]]++; break;}
            wasthere = 0;
        }
             wasthere = 0;
    }

    for(int i = 1 ; i <= cmax ; i++){
       //cout<<val[i]<<" ";
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num ;
int a[3000003];
int val[3000003];
set <int> st;
set <int>::iterator it;
bool wasthere = 0;
int main(){
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        num = a[i];
        while(a[i] > 1){
            for(int j = 2 ; j <= num/2 ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; wasthere = 1; break;}
            }
            if(!wasthere) { st.insert(a[i]); break; }
        }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++;
             }
             st.clear();
    }

    for(int i = 1 ; i <= cmax ; i++){
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt;
int a[30000003];
int val[30000003];
int primes[200000002];
bool wasthere = 0;
int main(){
    for(int i = 2 ; i <= 10000000 ; i++){
        if(primes[i] == 0){
            primes[i] = i;
        for(int j = i*2 ; j <= 10000000 ; j+=i)
        if(primes[j] == 0) primes[j] = i;
        }
    }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        while(a[i] > 1){
           int f =  val[primes[a[i]]]++;
            while((a[i] % primes[a[i]]) == 0){
                a[i] = a[i] / primes[a[i]];
               if(primes[a[i]!=f]) val[primes[a[i]]]++;
                if(a[i]==1) break;
            }

        }
    }

    for(int i = 1 ; i <= cmax ; i++){
     //cout<<val[i]<<" ";
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax ;
int a[1000000];
int val[100000];
int primes[100000] , r_primes[100000];
set <int> st;
set <int>::iterator it;
int main(){
    for(int i = 2 ; i <= sqrt(100000) ; i++){
        for(int j = i ; j < 100000/i ; j++){
            r_primes[i*j] = 1;
        }
    }
    for(int i = 1 ; i <= 100000 ; i++){
        primes[i]++;
    }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        while(a[i] > 1){
            for(int j = 2 ; j <= a[i] ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; break;}
            }
        }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++; cmax = max(*it,cmax);
             }
             st.clear();
    }
    // for(int i = 1  ; i <= cmax ; i++){
    //     val[i] += val[i-1];
    // }
    for(int i = 1 ; i <= cmax ; i++){
        val[i] += val[i-1];
    }
    cin>>m;
    for(int i = 0; i < m ; i++) {
        cin>>l>>r;
       if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
       else {cout<<val[r]-val[l-1]<<endl;}
        }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax ;
int a[3000003];
int val[3000003];
set <int> st;
set <int>::iterator it;
int main(){
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        while(a[i] > 1){
            for(int j = 2 ; j <= a[i] ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; break;}
            }
        }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++;
             }
             st.clear();
    }
    for(int i = 1 ; i <= cmax ; i++){
        val[i] += val[i-1];
    }
    cin>>m;
    for(int i = 0; i < m ; i++) {
        cin>>l>>r;
        if(l < cmax){
       if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
       else {cout<<val[r]-val[l-1]<<endl;}
        }
        else cout<<0<<endl;
}
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int a[1000000] , b[1000000] , n , r , l , c , m ,cnt , x ,sum , cmax , findex, sindex;
int val[3000003];
int primes[3000003];
bool flag = 0;
int main(){
        //*here i get prime numbers
        for(int i = 2 ; i < sqrt(10000) ; i++){
            for(int j = i ; j <= 10000/i ; j++ ){
                a[i*j] = 1;
            }
        }
        for(int i = 2 ; i <= 10000 ; i++){
            if(a[i]!=1) primes[cnt++] = i;
        }
        //*here i finished dragging them into array
         cin>>n;
    for(int i = 0 ; i <  n ; i++){
        cin>>b[i]; cmax = max(b[i],cmax); //biggest number input
    }

    cin>>m;
    for(int k = 0 ; k < m ; k++){
        cin>>l>>r;
         for(int j = 0 ; j < n ; j ++)  val[b[j]] = 0;
         findex = -1; sindex = -1;
         for(int i = 0 ; i < cnt ; i++) {
             if(primes[i] > r) break;
             if(primes[i] >= l && !flag ) { findex = i; flag = 1; }
             if(primes[i] <= r) sindex = i;
         }

         flag = 0;

   if(findex!=-1 && sindex!=-1){
        for(int i = findex ; i <= sindex ; i++){
       if(primes[i] > r) break;
       if(primes[i] >= l){
          for(int j = primes[i] ; j <= cmax ; j+=primes[i]){
                 val[j]++;
          }
       }
     }
    for(int i = 0 ; i < n ; i++) sum+=val[b[i]];
     cout<<sum<<endl;
   }
    else cout<<0<<endl;
     sum = 0;
    }

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt , b , f;
int val[100000001];
int primes[100000001];
int main(){
    for(int i = 2 ; i <= 10000000 ; i++){
        if(primes[i] == 0){
            primes[i] = i;
        for(int j = i*2 ; j <= 10000000 ; j+=i)
        if(primes[j] == 0) primes[j] = i;
        }
    }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>b; cmax = max(b,cmax);
        while(b > 1){
            val[primes[b]]++;
            f = primes[b];
            while((b % f) == 0){
                b /= f;
               //if(primes[a[i]!=f])
              // val[primes[b]]++;
                //if(a[i]==1) break;
            }

        }
    }

    for(int i = 1 ; i <= cmax ; i++){
     //cout<<val[i]<<" ";
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int a[1000000] , b[1000000] , n , r , l , c , m ,cnt , x ,sum , cmax , findex, sindex;
int val[3000003];
int primes[3000003];
bool flag = 0;
int main(){
        //*here i get prime numbers
        for(int i = 2 ; i < sqrt(1000) ; i++){
            for(int j = i ; j <= 1000/i ; j++ ){
                a[i*j] = 1;
            }
        }
        for(int i = 2 ; i <= 100000 ; i++){
            if(a[i]!=1) primes[cnt++] = i;
        }
        //*here i finished dragging them into array
         cin>>n;
    for(int i = 0 ; i <  n ; i++){
        cin>>b[i]; cmax = max(b[i],cmax); //biggest number input
    }

    cin>>m;
    for(int k = 0 ; k < m ; k++){
        cin>>l>>r;
         for(int j = 0 ; j < n ; j ++)  val[b[j]] = 0;
         findex = -1; sindex = -1;
         for(int i = 0 ; i < cnt ; i++) {
             if(primes[i] > r) break;
             if(primes[i] >= l && !flag ) { findex = i; flag = 1; }
             if(primes[i] <= r) sindex = i;
         }

         flag = 0;

   if(findex!=-1 && sindex!=-1){
        for(int i = findex ; i <= sindex ; i++){
       if(primes[i] > r) break;
       if(primes[i] >= l){
          for(int j = primes[i] ; j <= cmax ; j+=primes[i]){
                 val[j]++;
          }
       }
     }
    for(int i = 0 ; i < n ; i++) sum+=val[b[i]];
     cout<<sum<<endl;
   }
    else cout<<0<<endl;
     sum = 0;
    }

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax , num  , cnt;
int a[30000003];
int val[30000003];
int re_primes[30000003];
int primes[300000003];
bool wasthere = 0;
int main(){
    for(int i = 2 ; i <= 10000000 ; i++){
        if(primes[i] == 0){
            primes[i] = i;
        for(int j = i*2 ; j <= 10000000 ; j+=i)
        if(primes[j] == 0) primes[j] = i;
        }
    }
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        while(a[i] > 1){
           int f =  val[primes[a[i]]]++;
            while((a[i] % primes[a[i]]) == 0){
                a[i] = a[i] / primes[a[i]];
               if(primes[a[i]!=f]) val[primes[a[i]]]++;
                if(a[i]==1) break;
            }

        }
    }

    for(int i = 1 ; i <= cmax ; i++){
     //cout<<val[i]<<" ";
       val[i] += val[i-1];
    }
        cin>>m;
        for(int i = 0; i < m ; i++) {
            cin>>l>>r;
            if(l < cmax){
        if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
        else {cout<<val[r]-val[l-1]<<endl;}
            }
            else cout<<0<<endl;
    }
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int a[1000000] , b[1000000] , n , r , l , c , m ,cnt , x ,sum , cmax , findex, sindex;
int val[3000003];
int primes[3000003];
bool flag = 0;
int main(){
        //*here i get prime numbers
        for(int i = 2 ; i < sqrt(9000) ; i++){
            for(int j = i ; j <= 9000/i ; j++ ){
                a[i*j] = 1;
            }
        }
        for(int i = 2 ; i <= 100000 ; i++){
            if(a[i]!=1) primes[cnt++] = i;
        }
        //*here i finished dragging them into array
         cin>>n;
    for(int i = 0 ; i <  n ; i++){
        cin>>b[i]; cmax = max(b[i],cmax); //biggest number input
    }

    cin>>m;
    for(int k = 0 ; k < m ; k++){
        cin>>l>>r;
         for(int j = 0 ; j < n ; j ++)  val[b[j]] = 0;
         findex = -1; sindex = -1;
         for(int i = 0 ; i < cnt ; i++) {
             if(primes[i] > r) break;
             if(primes[i] >= l && !flag ) { findex = i; flag = 1; }
             if(primes[i] <= r) sindex = i;
         }

         flag = 0;

   if(findex!=-1 && sindex!=-1){
        for(int i = findex ; i <= sindex ; i++){
       if(primes[i] > r) break;
       if(primes[i] >= l){
          for(int j = primes[i] ; j <= cmax ; j+=primes[i]){
                 val[j]++;
          }
       }
     }
    for(int i = 0 ; i < n ; i++) sum+=val[b[i]];
     cout<<sum<<endl;
   }
    else cout<<0<<endl;
     sum = 0;
    }

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , l , r ,cmax ;
int a[3000003];
int val[3000003];
set <int> st;
set <int>::iterator it;
int main(){
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i]; cmax = max(a[i],cmax);
        while(a[i] > 1){
            for(int j = 2 ; j <= a[i] ; j++){
                if(a[i]%j==0) {st.insert(j); a[i]/=j; break;}
            }
        }
        for(it = st.begin() ; it!=st.end() ; it++){
          val[*it]++; cmax = max(*it,cmax);
             }
             st.clear();
    }
    for(int i = 1 ; i <= cmax ; i++){
        val[i] += val[i-1];
    }
    cin>>m;
    for(int i = 0; i < m ; i++) {
        cin>>l>>r;
       if(r > cmax) {cout<<val[cmax] - val[l-1]<<endl;}
       else {cout<<val[r]-val[l-1]<<endl;}
        }
}