#include <cstdio>
#include <algorithm>

using namespace std;

struct arbint {
    int g, m, num_m;
};

arbint aint [4 * 10011 + 10];

int s [10011];
int l, r, poz, value;
arbint temp;

int gcd (int a, int b) {
    int r;
    while (b) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

void update (int nod, int st, int dr) {
    int med;
    if (st == dr) {
        aint [nod].g = aint [nod].m = value;
        aint [nod].num_m = 1;
        return ;
    }
    med = (st + dr) / 2;
    if (poz <= med)
        update (nod << 1, st, med);
    else update ((nod << 1) + 1, med + 1, dr);
    aint [nod].m = min (aint [nod << 1].m, aint [(nod << 1) + 1].m);
    aint [nod].num_m = 0;
    if (aint [nod].m == aint [nod << 1].m)
        aint [nod].num_m += aint [nod << 1].num_m;
    if (aint [nod].m == aint [(nod << 1) + 1].m)
        aint [nod].num_m += aint [(nod << 1) + 1].num_m;
    aint [nod].g = gcd (aint [nod << 1].g, aint [(nod << 1) + 1].g);
}

void query (int nod, int st, int dr) {
    int med;
    if (l <= st && dr <= r) {
        temp.g = gcd (temp.g, aint [nod].g);
        if (temp.m == aint [nod].m)
            temp.num_m += aint [nod].num_m;
        if (temp.m > aint [nod].m) {
            temp.m = aint [nod].m;
            temp.num_m = aint [nod].num_m;
        }
        return;
    }
    med = (st + dr) / 2;
    if (l <= med)
        query (nod << 1, st, med);
    if (r > med)
        query ((nod << 1) + 1, med + 1, dr);
}

int main () {
    int n, i, t;

   /* freopen ("F.in", "r", stdin);
    freopen ("F.out", "w", stdout);*/

    scanf ("%d", &n);
    for (i = 1; i <= n; i ++) {
        scanf ("%d", &s [i]);
        value = s [i];
        poz = i;
        update (1, 1, n);
    }
    scanf ("%d", &t);
    for (i = 1; i <= t; i ++) {
        scanf ("%d%d", &l, &r);
        temp.m = (1ll << 31) - 1;
        temp.g = 0;
        query (1, 1, n);
        if (temp.g == temp.m)
            printf ("%d\n", r - l + 1 - temp.num_m);
        else printf ("%d\n", r - l + 1);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

struct arbint {
    int g, m, num_m;
};

arbint aint [4 * 10011 + 10];

int s [10011];
int l, r, poz, value;
arbint temp;

int gcd (int a, int b) {
    int r;
    while (b) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

void update (int nod, int st, int dr) {
    int med;
    if (st == dr) {
        aint [nod].g = aint [nod].m = value;
        aint [nod].num_m = 1;
        return ;
    }
    med = (st + dr) / 2;
    if (poz <= med)
        update (nod * 2, st, med);
    else update (nod * 2 + 1, med + 1, dr);

    aint [nod].m = min (aint [nod * 2].m, aint [nod * 2 + 1].m);
    aint [nod].num_m = 0;

    if (aint [nod].m == aint [nod * 2].m)
        aint [nod].num_m += aint [nod * 2].num_m;

    if (aint [nod].m == aint [nod * 2 + 1].m)
        aint [nod].num_m += aint [nod * 2 + 1].num_m;

    aint [nod].g = gcd (aint [nod * 2].g, aint [nod * 2 + 1].g);
}

void query (int nod, int st, int dr) {
    int med;
    if (l <= st && dr <= r) {
        temp.g = gcd (temp.g, aint [nod].g);

        if (temp.m == aint [nod].m)
            temp.num_m += aint [nod].num_m;
        else
            if (temp.m > aint [nod].m) {
                temp.m = aint [nod].m;
                temp.num_m = aint [nod].num_m;
            }
        return;
    }
    med = (st + dr) / 2;
    if (l <= med)
        query (nod * 2, st, med);
    if (r > med)
        query (nod * 2 + 1, med + 1, dr);
}

int main () {
    int n, i, t;

    /*freopen ("F.in", "r", stdin);
    freopen ("F.out", "w", stdout);*/

    scanf ("%d", &n);
    for (i = 1; i <= n; i ++) {
        scanf ("%d", &s [i]);
        value = s [i];
        poz = i;
        update (1, 1, n);
    }
    scanf ("%d", &t);
    for (i = 1; i <= t; i ++) {
        scanf ("%d%d", &l, &r);
        temp.m = (1ll << 31) - 1;
        temp.g = 0;
        temp.num_m = 0;
        query (1, 1, n);
        if (temp.g == temp.m)
            printf ("%d\n", r - l + 1 - temp.num_m);
        else printf ("%d\n", r - l + 1);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

struct arbint {
    int g, m, num_m;
};

arbint aint [4 * 100011 + 10];

int s [100011];
int l, r, poz, value;
arbint temp;

int gcd (int a, int b) {
    int r;
    while (b) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

void update (int nod, int st, int dr) {
    int med;
    if (st == dr) {
        aint [nod].g = aint [nod].m = s [st];
        aint [nod].num_m = 1;
        return ;
    }

    med = (st + dr) / 2;

    update (nod * 2, st, med);
    update (nod * 2 + 1, med + 1, dr);

    aint [nod].m = min (aint [nod * 2].m, aint [nod * 2 + 1].m);
    aint [nod].num_m = 0;

    if (aint [nod].m == aint [nod * 2].m)
        aint [nod].num_m += aint [nod * 2].num_m;

    if (aint [nod].m == aint [nod * 2 + 1].m)
        aint [nod].num_m += aint [nod * 2 + 1].num_m;

    aint [nod].g = gcd (aint [nod * 2].g, aint [nod * 2 + 1].g);
}

void query (int nod, int st, int dr) {
    int med;
    if (l <= st && dr <= r) {
        temp.g = gcd (temp.g, aint [nod].g);

        if (temp.m == aint [nod].m)
            temp.num_m += aint [nod].num_m;
        else
            if (temp.m > aint [nod].m) {
                temp.m = aint [nod].m;
                temp.num_m = aint [nod].num_m;
            }
        return;
    }
    med = (st + dr) / 2;
    if (l <= med)
        query (nod * 2, st, med);
    if (r > med)
        query (nod * 2 + 1, med + 1, dr);
}

int main () {
    int n, i, t;

    /*freopen ("F.in", "r", stdin);
    freopen ("F.out", "w", stdout);*/

    scanf ("%d", &n);
    for (i = 1; i <= n; i ++) {
        scanf ("%d", &s [i]);
    }
    update (1, 1, n);
    scanf ("%d", &t);
    for (i = 1; i <= t; i ++) {
        scanf ("%d%d", &l, &r);
        temp.m = (1ll << 31) - 1;
        temp.g = 0;
        temp.num_m = 0;
        query (1, 1, n);
        if (temp.g == temp.m)
            printf ("%d\n", r - l + 1 - temp.num_m);
        else printf ("%d\n", r - l + 1);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

struct arbint {
    int g, m, num_m;
};

arbint aint [4 * 10011 + 10];

int s [10011];
int l, r, poz, value;
arbint temp;

int gcd (int a, int b) {
    int r;
    while (b) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

void update (int nod, int st, int dr) {
    int med;
    if (st == dr) {
        aint [nod].g = aint [nod].m = s [st];
        aint [nod].num_m = 1;
        return ;
    }

    med = (st + dr) / 2;

    update (nod * 2, st, med);
    update (nod * 2 + 1, med + 1, dr);

    aint [nod].m = min (aint [nod * 2].m, aint [nod * 2 + 1].m);
    aint [nod].num_m = 0;

    if (aint [nod].m == aint [nod * 2].m)
        aint [nod].num_m += aint [nod * 2].num_m;

    if (aint [nod].m == aint [nod * 2 + 1].m)
        aint [nod].num_m += aint [nod * 2 + 1].num_m;

    aint [nod].g = gcd (aint [nod * 2].g, aint [nod * 2 + 1].g);
}

void query (int nod, int st, int dr) {
    int med;
    if (l <= st && dr <= r) {
        temp.g = gcd (temp.g, aint [nod].g);

        if (temp.m == aint [nod].m)
            temp.num_m += aint [nod].num_m;
        else
            if (temp.m > aint [nod].m) {
                temp.m = aint [nod].m;
                temp.num_m = aint [nod].num_m;
            }
        return;
    }
    med = (st + dr) / 2;
    if (l <= med)
        query (nod * 2, st, med);
    if (r > med)
        query (nod * 2 + 1, med + 1, dr);
}

int main () {
    int n, i, t;

    /*freopen ("F.in", "r", stdin);
    freopen ("F.out", "w", stdout);*/

    scanf ("%d", &n);
    for (i = 1; i <= n; i ++) {
        scanf ("%d", &s [i]);
    }
    update (1, 1, n);
    scanf ("%d", &t);
    for (i = 1; i <= t; i ++) {
        scanf ("%d%d", &l, &r);
        temp.m = (1ll << 31) - 1;
        temp.g = 0;
        temp.num_m = 0;
        query (1, 1, n);
        if (temp.g == temp.m)
            printf ("%d\n", r - l + 1 - temp.num_m);
        else printf ("%d\n", r - l + 1);
    }
    return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e5+10;
struct Seg
{
	int bo[2],so[2],g;
}t[M<<4];
int num[M],tot=0;
int n,cnt=1,rt,m;
typedef pair<int, int> pii;
pii ans[M];
inline int read()
{
	int x=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
inline int gcd(int a,int b)
{
	if (a%b==0) return b;
	return gcd(b,a%b);
}
inline void pushup(int x)
{
	int ls=t[x].so[0];
	int rs=t[x].so[1];
	t[x].bo[0]=t[ls].bo[0];
	t[x].bo[1]=t[rs].bo[1];
	t[x].g=gcd(t[ls].g,t[rs].g);
	return ;
}
inline void built(int l,int r,int x)
{
	if (l==r)
	{
		scanf("%d",&ans[++tot].first);
		ans[tot].second=tot;
		t[x].bo[0]=t[x].bo[1]=l;
		t[x].so[0]=t[x].so[1]=-1;
		return (void)(t[x].g=ans[tot].first);
	}
	int mid=(l+r)>>1;
	t[x].so[0]=++cnt;t[x].so[1]=++cnt;
	built(l,mid,t[x].so[0]);built(mid+1,r,t[x].so[1]);
	pushup(x);
	return ;
}
inline int query(int l,int r,int x)
{
	if (l<=t[x].bo[0]&&t[x].bo[1]<=r) return t[x].g;
	int mid=(t[x].bo[0]+t[x].bo[1])>>1;int a1=0,a2=0;
	if (l<=mid) a1=query(l,r,t[x].so[0]);
	if (r>mid) a2=query(l,r,t[x].so[1]);
	return gcd(a1,a2);
}
int main()
{
	n=read();
	built(1,n,rt);int l,r;
	m=read();
	sort(ans+1,ans+n+1);
	for (int i=1;i<=m;i++)
	{
		l=read();r=read();int G=query(l,r,rt);
		int a=lower_bound(ans+1,ans+n+1,pii(G,l))-(ans+1);
		int b=lower_bound(ans+1,ans+n+1,pii(G,r+1))-(ans+1);
		cout<<(r-l+1)-(b-a)<<endl;
		tot=0;
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=5e5;
struct Seg
{
	int bo[2],so[2],g;
}t[M];
int num[M],tot=0;
int n,cnt=1,rt,m;
typedef pair<int, int> pii;
pii ans[M];
inline int read()
{
	int x=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
inline int gcd(int a,int b)
{
	if (a%b==0) return b;
	return gcd(b,a%b);
}
inline void pushup(int x)
{
	int ls=t[x].so[0];
	int rs=t[x].so[1];
	t[x].bo[0]=t[ls].bo[0];
	t[x].bo[1]=t[rs].bo[1];
	t[x].g=gcd(t[ls].g,t[rs].g);
	return ;
}
inline void built(int l,int r,int x)
{
	if (l==r)
	{
		scanf("%d",&ans[++tot].first);
		ans[tot].second=tot;
		t[x].bo[0]=t[x].bo[1]=l;
		t[x].so[0]=t[x].so[1]=-1;
		return (void)(t[x].g=ans[tot].first);
	}
	int mid=(l+r)>>1;
	t[x].so[0]=++cnt;t[x].so[1]=++cnt;
	built(l,mid,t[x].so[0]);built(mid+1,r,t[x].so[1]);
	pushup(x);
	return ;
}
inline int query(int l,int r,int x)
{
	if (l<=t[x].bo[0]&&t[x].bo[1]<=r) return t[x].g;
	int mid=(t[x].bo[0]+t[x].bo[1])>>1;int a1=0,a2=0;
	if (l<=mid) a1=query(l,r,t[x].so[0]);
	if (r>mid) a2=query(l,r,t[x].so[1]);
	return gcd(a1,a2);
}
int main()
{
	n=read();
	built(1,n,rt);int l,r;
	m=read();
	sort(ans+1,ans+n+1);
	for (int i=1;i<=m;i++)
	{
		l=read();r=read();int G=query(l,r,rt);
		int a=lower_bound(ans+1,ans+n+1,pii(G,l))-(ans+1);
		int b=lower_bound(ans+1,ans+n+1,pii(G,r+1))-(ans+1);
		cout<<(r-l+1)-(b-a)<<endl;
		tot=0;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define ll long long
const int maxn = 1e5 + 10;
int gcd[maxn<<2];
int Min[maxn<<2];
typedef pair<int, int> pii;
pii num[maxn];
int Gcd(int a,int b)
{
	if (!b) return a;
	return Gcd(b,a%b);
}
void PushUp(int rt) {
    gcd[rt] = Gcd(gcd[rt<<1], gcd[rt<<1|1]);
}
int cnt = 0;
void build(int l, int r, int rt) {
    if(l == r) {
        //printf("cc %d\n", ++tmp);
        scanf("%d", &num[++cnt].first);
        num[cnt].second = cnt;
        gcd[rt] = num[cnt].first;
        return;
    }
    int m = (l + r) >> 1;
    build(lson);
    build(rson);
    PushUp(rt);
}
int query(int L, int R, int l, int r, int rt) {
    if(L <= l && r <= R) {
        return gcd[rt];
    }
    int a = 0, b = 0;
    int m = (l + r) >> 1;
    if(L <= m) a = query(L, R, lson);
    if(m < R) b = query(L, R, rson);
    return Gcd(a, b);
}

int main() {
    int n;
    scanf("%d", &n);
    build(1, n, 1);
    int q;
    sort(num + 1, num + 1 + n);
    scanf("%d", &q);
    while(q--)
	{
        int a, b;
        scanf("%d %d", &a, &b);
        int G= query(a, b, 1, n, 1);
        int l = lower_bound(num + 1, num + 1 + n, pii(G, a)) - (num + 1);
        int r = lower_bound(num + 1, num + 1 + n, pii(G, b + 1)) - (num + 1);
        printf("%d\n", (b - a + 1) - (r - l));
        cnt = 0;
    }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define ll long long
const int maxn = 1e5 + 10;
int gcd[maxn<<2];
int Min[maxn<<2];
typedef pair<int, int> pii;
pii num[maxn];
void PushUp(int rt) {
    gcd[rt] = __gcd(gcd[rt<<1], gcd[rt<<1|1]);
}
int cnt = 0;
void build(int l, int r, int rt) {
    if(l == r) {
        //printf("cc %d\n", ++tmp);
        scanf("%d", &num[++cnt].first);
        num[cnt].second = cnt;
        gcd[rt] = num[cnt].first;
        return;
    }
    int m = (l + r) >> 1;
    build(lson);
    build(rson);
    PushUp(rt);
}
int query(int L, int R, int l, int r, int rt) {
    if(L <= l && r <= R) {
        return gcd[rt];
    }
    int a = 0, b = 0;
    int m = (l + r) >> 1;
    if(L <= m) a = query(L, R, lson);
    if(m < R) b = query(L, R, rson);
    return __gcd(a, b);
}

int main() {
    int n;
    scanf("%d", &n);
    build(1, n, 1);
    int q;
    sort(num + 1, num + 1 + n);
    scanf("%d", &q);
    while(q--)
	{
        int a, b;
        scanf("%d %d", &a, &b);
        int G= query(a, b, 1, n, 1);
        int l = lower_bound(num + 1, num + 1 + n, pii(G, a)) - (num + 1);
        int r = lower_bound(num + 1, num + 1 + n, pii(G, b + 1)) - (num + 1);
        printf("%d\n", (b - a + 1) - (r - l));
        cnt = 0;
    }
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e5+10;
struct Seg
{
	int bo[2],so[2],g;
}t[M<<4];
int num[M],tot=0;
int n,cnt=1,rt,m;
typedef pair<int, int> pii;
pii ans[M];
inline int read()
{
	int x=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
inline int gcd(int a,int b)
{
	if (!b) return a;
	return gcd(b,a%b);
}
inline void pushup(int x)
{
	int ls=t[x].so[0];
	int rs=t[x].so[1];
	t[x].bo[0]=t[ls].bo[0];
	t[x].bo[1]=t[rs].bo[1];
	t[x].g=gcd(t[ls].g,t[rs].g);
	return ;
}
inline void built(int l,int r,int x)
{
	if (l==r)
	{
		scanf("%d",&ans[++tot].first);
		ans[tot].second=tot;
		t[x].bo[0]=t[x].bo[1]=l;
		t[x].so[0]=t[x].so[1]=-1;
		return (void)(t[x].g=ans[tot].first);
	}
	int mid=(l+r)>>1;
	t[x].so[0]=++cnt;t[x].so[1]=++cnt;
	built(l,mid,t[x].so[0]);built(mid+1,r,t[x].so[1]);
	pushup(x);
	return ;
}
inline int query(int l,int r,int x)
{
	if (l<=t[x].bo[0]&&t[x].bo[1]<=r) return t[x].g;
	int mid=(t[x].bo[0]+t[x].bo[1])>>1;int a1=0,a2=0;
	if (l<=mid) a1=query(l,r,t[x].so[0]);
	if (r>mid) a2=query(l,r,t[x].so[1]);
	return gcd(a1,a2);
}
int main()
{
	n=read();
	built(1,n,rt);int l,r;
	m=read();
	sort(ans+1,ans+n+1);
	for (int i=1;i<=m;i++)
	{
		l=read();r=read();int G=query(l,r,rt);
		int a=lower_bound(ans+1,ans+n+1,pii(G,l))-(ans+1);
		int b=lower_bound(ans+1,ans+n+1,pii(G,r+1))-(ans+1);
		cout<<(r-l+1)-(b-a)<<endl;
		tot=0;
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=3e5;
struct Seg
{
	int bo[2],so[2],g;
}t[M];
int num[M],tot=0;
int n,cnt=1,rt,m;
typedef pair<int, int> pii;
pii ans[M];
inline int read()
{
	int x=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
inline int gcd(int a,int b)
{
	if (a%b==0) return b;
	return gcd(b,a%b);
}
inline void pushup(int x)
{
	int ls=t[x].so[0];
	int rs=t[x].so[1];
	t[x].bo[0]=t[ls].bo[0];
	t[x].bo[1]=t[rs].bo[1];
	t[x].g=gcd(t[ls].g,t[rs].g);
	return ;
}
inline void built(int l,int r,int x)
{
	if (l==r)
	{
		scanf("%d",&ans[++tot].first);
		ans[tot].second=tot;
		t[x].bo[0]=t[x].bo[1]=l;
		t[x].so[0]=t[x].so[1]=-1;
		return (void)(t[x].g=ans[tot].first);
	}
	int mid=(l+r)>>1;
	t[x].so[0]=++cnt;t[x].so[1]=++cnt;
	built(l,mid,t[x].so[0]);built(mid+1,r,t[x].so[1]);
	pushup(x);
	return ;
}
inline int query(int l,int r,int x)
{
	if (l<=t[x].bo[0]&&t[x].bo[1]<=r) return t[x].g;
	int mid=(t[x].bo[0]+t[x].bo[1])>>1;int a1=0,a2=0;
	if (l<=mid) a1=query(l,r,t[x].so[0]);
	if (r>mid) a2=query(l,r,t[x].so[1]);
	return gcd(a1,a2);
}
int main()
{
	n=read();
	built(1,n,rt);int l,r;
	m=read();
	sort(ans+1,ans+n+1);
	for (int i=1;i<=m;i++)
	{
		l=read();r=read();int G=query(l,r,rt);
		int a=lower_bound(ans+1,ans+n+1,pii(G,l))-(ans+1);
		int b=lower_bound(ans+1,ans+n+1,pii(G,r+1))-(ans+1);
		cout<<(r-l+1)-(b-a)<<endl;
		tot=0;
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=5e5;
struct Seg
{
	int bo[2],so[2],g;
}t[M];
typedef pair<int, int> pii;
pii num[M>>2];
int gcd(int a,int b)
{
	if (a%b==0) return b;
	return gcd(b,a%b);
}
void PushUp(int x)
{
   	int ls=t[x].so[0];
	int rs=t[x].so[1];
	t[x].bo[0]=t[ls].bo[0];
	t[x].bo[1]=t[rs].bo[1];
	t[x].g=gcd(t[ls].g,t[rs].g);
	return ;
}
int cnt=0,tot=1;
void build(int l, int r, int rt)
{
    if(l==r)
	{
        scanf("%d", &num[++cnt].first);
        num[cnt].second = cnt;
        t[rt].bo[0]=t[rt].bo[1]=l;
        t[rt].so[0]=t[rt].so[1]=-1;
		t[rt].g= num[cnt].first;
        return;
    }
    int m=(l+r)>>1;
    t[rt].so[0]=++tot;t[rt].so[1]=++tot;
    build(l,m,t[rt].so[0]);build(m+1,r,t[rt].so[1]);
    PushUp(rt);
    return ;
}
int query(int l, int r, int rt)
{
    if(l<=t[rt].bo[0]&& t[rt].bo[1]<=r) return t[rt].g;
    int a = 0, b = 0;
    int m = (t[rt].bo[0]+t[rt].bo[1])>>1;
    if(l<=m) a = query(l,r,t[rt].so[0]);
    if(m< r) b = query(l,r,t[rt].so[1]);
    return gcd(a, b);
}
int main()
{
    int n;
    scanf("%d",&n);
    build(1,n,0);
    int q;
    sort(num + 1, num + 1 + n);
    scanf("%d", &q);
    while(q--)
	{
        int a,b;
        scanf("%d %d", &a, &b);
        int G= query(a, b,0);
		int l = lower_bound(num + 1, num + 1 + n, pii(G, a)) - (num + 1);
        int r = lower_bound(num + 1, num + 1 + n, pii(G, b + 1)) - (num + 1);
		printf("%d\n", (b - a + 1) - (r - l));
        cnt = 0;
    }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define ll long long
const int maxn = 1e5 + 10;
int gcd[maxn<<2];
int Min[maxn<<2];
typedef pair<int, int> pii;
pii num[maxn];
int Gcd(int a,int b)
{
	if (a%b==0) return b;
	return Gcd(b,a%b);
}
void PushUp(int rt) {
    gcd[rt] = Gcd(gcd[rt<<1], gcd[rt<<1|1]);
}
int cnt = 0;
void build(int l, int r, int rt) {
    if(l == r) {
        //printf("cc %d\n", ++tmp);
        scanf("%d", &num[++cnt].first);
        num[cnt].second = cnt;
        gcd[rt] = num[cnt].first;
        return;
    }
    int m = (l + r) >> 1;
    build(lson);
    build(rson);
    PushUp(rt);
}
int query(int L, int R, int l, int r, int rt) {
    if(L <= l && r <= R) {
        return gcd[rt];
    }
    int a = 0, b = 0;
    int m = (l + r) >> 1;
    if(L <= m) a = query(L, R, lson);
    if(m < R) b = query(L, R, rson);
    return Gcd(a, b);
}

int main() {
    int n;
    scanf("%d", &n);
    build(1, n, 1);
    int q;
    sort(num + 1, num + 1 + n);
    scanf("%d", &q);
    while(q--)
	{
        int a, b;
        scanf("%d %d", &a, &b);
        int G= query(a, b, 1, n, 1);
        int l = lower_bound(num + 1, num + 1 + n, pii(G, a)) - (num + 1);
        int r = lower_bound(num + 1, num + 1 + n, pii(G, b + 1)) - (num + 1);
        printf("%d\n", (b - a + 1) - (r - l));
        cnt = 0;
    }
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e5;
struct Seg
{
	int bo[2],so[2],g;
}t[M];
int num[M],tot=0;
int n,cnt=1,rt,m;
typedef pair<int, int> pii;
pii ans[M];
inline int read()
{
	int x=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
inline int gcd(int a,int b)
{
	if (a%b==0) return b;
	return gcd(b,a%b);
}
inline void pushup(int x)
{
	int ls=t[x].so[0];
	int rs=t[x].so[1];
	t[x].bo[0]=t[ls].bo[0];
	t[x].bo[1]=t[rs].bo[1];
	t[x].g=gcd(t[ls].g,t[rs].g);
	return ;
}
inline void built(int l,int r,int x)
{
	if (l==r)
	{
		scanf("%d",&ans[++tot].first);
		ans[tot].second=tot;
		t[x].bo[0]=t[x].bo[1]=l;
		t[x].so[0]=t[x].so[1]=-1;
		return (void)(t[x].g=ans[tot].first);
	}
	int mid=(l+r)>>1;
	t[x].so[0]=++cnt;t[x].so[1]=++cnt;
	built(l,mid,t[x].so[0]);built(mid+1,r,t[x].so[1]);
	pushup(x);
	return ;
}
inline int query(int l,int r,int x)
{
	if (l<=t[x].bo[0]&&t[x].bo[1]<=r) return t[x].g;
	int mid=(t[x].bo[0]+t[x].bo[1])>>1;int a1=0,a2=0;
	if (l<=mid) a1=query(l,r,t[x].so[0]);
	if (r>mid) a2=query(l,r,t[x].so[1]);
	return gcd(a1,a2);
}
int main()
{
	n=read();
	built(1,n,rt);int l,r;
	m=read();
	sort(ans+1,ans+n+1);
	for (int i=1;i<=m;i++)
	{
		l=read();r=read();int G=query(l,r,rt);
		int a=lower_bound(ans+1,ans+n+1,pii(G,l))-(ans+1);
		int b=lower_bound(ans+1,ans+n+1,pii(G,r+1))-(ans+1);
		cout<<(r-l+1)-(b-a)<<endl;
		tot=0;
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e5+10;
struct Seg
{
	int bo[2],so[2],g;
}t[M<<4];
int num[M],tot=0;
int n,cnt=1,rt,m;
typedef pair<int, int> pii;
pii ans[M];
inline int read()
{
	int x=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
inline int gcd(int a,int b)
{
	if (!b) return a;
	return gcd(b,a%b);
}
inline void pushup(int x)
{
	int ls=t[x].so[0];
	int rs=t[x].so[1];
	t[x].bo[0]=t[ls].bo[0];
	t[x].bo[1]=t[rs].bo[1];
	t[x].g=gcd(t[ls].g,t[rs].g);
	return ;
}
inline void built(int l,int r,int x)
{
	if (l==r)
	{
		scanf("%d",&ans[++tot].first);
		ans[tot].second=tot;
		t[x].bo[0]=t[x].bo[1]=l;
		t[x].so[0]=t[x].so[1]=-1;
		return (void)(t[x].g=ans[tot].first);
	}
	int mid=(l+r)>>1;
	t[x].so[0]=++cnt;t[x].so[1]=++cnt;
	built(l,mid,t[x].so[0]);built(mid+1,r,t[x].so[1]);
	pushup(x);
	return ;
}
inline int query(int l,int r,int x)
{
	if (l<=t[x].bo[0]&&t[x].bo[1]<=r) return t[x].g;
	int mid=(t[x].bo[0]+t[x].bo[1])>>1;int a1=0,a2=0;
	if (l<=mid) a1=query(l,r,t[x].so[0]);
	if (r>mid) a2=query(l,r,t[x].so[1]);
	return gcd(a1,a2);
}
int main()
{
	n=read();
	built(1,n,rt);int l,r;
	m=read();
	sort(ans+1,ans+n+1);
	for (int i=1;i<=m;i++)
	{
		l=read();r=read();int G=query(l,r,rt);
		int a=lower_bound(ans+1,ans+n+1,pii(G,l))-(ans+1);
		int b=lower_bound(ans+1,ans+n+1,pii(G,r+1))-(ans+1);
		cout<<(r-l+1)-(b-a)<<endl;
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=5e5;
struct Seg
{
	int bo[2],so[2],g;
}t[M];
typedef pair<int, int> pii;
pii num[M>>2];
int gcd(int a,int b)
{
	if (a%b==0) return b;
	return gcd(b,a%b);
}
void PushUp(int x)
{
   	int ls=t[x].so[0];
	int rs=t[x].so[1];
	t[x].bo[0]=t[ls].bo[0];
	t[x].bo[1]=t[rs].bo[1];
	t[x].g=gcd(t[ls].g,t[rs].g);
	return ;
}
int cnt=0,tot=2;
void build(int l, int r, int rt)
{
    if(l==r)
	{
        scanf("%d", &num[++cnt].first);
        num[cnt].second = cnt;
        t[rt].bo[0]=t[rt].bo[1]=l;
        t[rt].so[0]=t[rt].so[1]=-1;
		t[rt].g= num[cnt].first;
        return;
    }
    int m=(l+r)>>1;
    t[rt].so[0]=++tot;t[rt].so[1]=++tot;
    build(l,m,t[rt].so[0]);build(m+1,r,t[rt].so[1]);
    PushUp(rt);
    return ;
}
int query(int l, int r, int rt)
{
    if(l<=t[rt].bo[0]&& t[rt].bo[1]<=r) return t[rt].g;
    int a = 0, b = 0;
    int m = (t[rt].bo[0]+t[rt].bo[1])>>1;
    if(l<=m) a = query(l,r,t[rt].so[0]);
    if(m< r) b = query(l,r,t[rt].so[1]);
    return gcd(a, b);
}
int main()
{
    int n;scanf("%d",&n);
    build(1,n,1);
    int q;scanf("%d", &q);
    sort(num+1,num+1+n);
    while(q--)
	{
        int a,b;
        scanf("%d%d",&a,&b);
        int G=query(a,b,1);
		int l=lower_bound(num+1,num+1+n,pii(G,a)) - (num + 1);
        int r=lower_bound(num+1,num+1+n,pii(G,b+1)) - (num + 1);
		printf("%d\n", (b - a + 1) - (r - l));
        cnt = 0;
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct f{
    int pos,nr;
}v[100005];
int n,gcd[400005],arb[400005],t,a,b,ch,mn,d,rez[100005],val,nrm[100005],k=1,init[100005];
string s;
vector<int> vct[100005];

int MIN(int x,int y)
{
    if(!x || !y) return max(x,y);
    return min(x,y);
}

int GCD(int x,int y)
{
    if(!x || !y) return max(x,y);
    int r=x%y;
    while(r)
    {
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}

void updategcd(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        gcd[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updategcd(nod*2,lt,md,pos);
    else updategcd(nod*2+1,md+1,rt,pos);

    gcd[nod]=GCD(gcd[nod*2],gcd[nod*2+1]);
}

void updatemin(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        arb[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updatemin(nod*2,lt,md,pos);
    else updatemin(nod*2+1,md+1,rt,pos);

    arb[nod]=MIN(arb[nod*2],arb[nod*2+1]);
}

void query(int nod,int lt,int rt,int x,int y)
{
    if(x<=lt && rt<=y)
    {
        mn=MIN(mn,arb[nod]);
        d=GCD(d,gcd[nod]);
        return;
    }
    if(lt==rt) return;
    int md=(lt+rt)/2;
    if(md>=x) query(nod*2,lt,md,x,y);
    if(md<y) query(nod*2+1,md+1,rt,x,y);
}

int nextint()
{
    int num=0;
    while(s[ch]==' ') ++ch;
    while(s[ch]>='0' && s[ch]<='9')
    {
        num=num*10+s[ch]-'0';
        ++ch;
    }
    return num;
}

bool comp(f x, f y)
{
    if(x.nr==y.nr) return(x.pos<y.pos);
    return(x.nr<y.nr);
}

void normalizare()
{
    sort(v+1,v+n+1,comp);
    int p=0,l=v[1].nr;
    nrm[1]=l;
    while(p<n)
    {
        ++p;
        if(l==v[p].nr) vct[k].push_back(v[p].pos);
        else
        {
            l=v[p].nr;
            ++k;
            nrm[k]=l;
            vct[k].push_back(v[p].pos);
        }
    }
}

int nrvalues(int mn,int u,int w)
{
    int mr=0;
    for(int i=1;i<=n;++i)
    {
        if(init[i]==mn && i>=u && i<=w) ++mr;
    }
    return mr;
}

void afisare()
{
    for(int i=1;i<=t;++i)
    {
        cout<<rez[i]<<'\n';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    getline(cin,s); n=nextint();
    getline(cin,s); ch=0;
    for(int i=1;i<=n;++i)
    {
        val=nextint();
        init[i]=val;
        v[i].nr=val;
        v[i].pos=i;
        updategcd(1,1,n,i);
        updatemin(1,1,n,i);
    }

    normalizare();

    getline(cin,s); ch=0; t=nextint();
    for(int i=1;i<=t;++i)
    {
        getline(cin,s); ch=0;
        a=nextint(); b=nextint();
        mn=d=0;
        query(1,1,n,a,b);
        if(mn!=d) rez[i]=b-a+1;
        else
        {
            rez[i]=b-a+1-nrvalues(mn,a,b);
        }
    }
    afisare();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct f{
    int pos,nr;
}v[100005];
int n,gcd[400005],arb[400005],t,a,b,ch,mn,d,rez[100005],val,nrm[100005],k=1;
string s;
vector<int> vct[100005];

int MIN(int x,int y)
{
    if(!x || !y) return max(x,y);
    return min(x,y);
}

int GCD(int x,int y)
{
    if(!x || !y) return max(x,y);
    int r=x%y;
    while(r)
    {
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}

void updategcd(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        gcd[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updategcd(nod*2,lt,md,pos);
    else updategcd(nod*2+1,md+1,rt,pos);

    gcd[nod]=GCD(gcd[nod*2],gcd[nod*2+1]);
}

void updatemin(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        arb[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updatemin(nod*2,lt,md,pos);
    else updatemin(nod*2+1,md+1,rt,pos);

    arb[nod]=MIN(arb[nod*2],arb[nod*2+1]);
}

void query(int nod,int lt,int rt,int x,int y)
{
    if(x<=lt && rt<=y)
    {
        mn=MIN(mn,arb[nod]);
        d=GCD(d,gcd[nod]);
        return;
    }
    if(lt==rt) return;
    int md=(lt+rt)/2;
    if(md>=x) query(nod*2,lt,md,x,y);
    if(md<y) query(nod*2+1,md+1,rt,x,y);
}

int nextint()
{
    int num=0;
    while(s[ch]==' ') ++ch;
    while(s[ch]>='0' && s[ch]<='9')
    {
        num=num*10+s[ch]-'0';
        ++ch;
    }
    return num;
}

bool comp(f x, f y)
{
    if(x.nr==y.nr) return(x.pos<y.pos);
    return(x.nr<y.nr);
}

void normalizare()
{
    sort(v+1,v+n+1,comp);
    int p=0,l=v[1].nr;
    nrm[1]=l;
    while(p<n)
    {
        ++p;
        if(l==v[p].nr) vct[k].push_back(v[p].pos);
        else
        {
            l=v[p].nr;
            ++k;
            nrm[k]=l;
            vct[k].push_back(v[p].pos);
        }
    }
}

int nrvalues(int mn,int u,int w)
{
    //seach position for x in normalization
    int md,pos,up,lw,lt,rt;
    lt=1; rt=k+1;
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(mn<nrm[md]) rt=md;
        else lt=md;
    }
    pos=lt;
    //lower bound in vct[pos]
    lt=0; rt=vct[pos].size();
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(u<vct[pos][md]) rt=md;
        else lt=md;
    }
    lw=lt;
    while(vct[pos][lw]<u) ++lw;
    //upper bound
    lt=0; rt=vct[pos].size();
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(w<=vct[pos][md]) lt=md;
        else rt=md;
    }
    up=lt;
    while(vct[pos][up]>w) --up;

    return (up-lw+1);
}

void afisare()
{
    for(int i=1;i<=t;++i)
    {
        cout<<rez[i]<<'\n';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    getline(cin,s); n=nextint();
    getline(cin,s); ch=0;
    for(int i=1;i<=n;++i)
    {
        val=nextint();
        v[i].nr=val;
        v[i].pos=i;
        updategcd(1,1,n,i);
        updatemin(1,1,n,i);
    }

    normalizare();

    getline(cin,s); ch=0; t=nextint();
    for(int i=1;i<=t;++i)
    {
        getline(cin,s); ch=0;
        a=nextint(); b=nextint();
        mn=d=0;
        query(1,1,n,a,b);
        if(mn!=d) rez[i]=b-a+1;
        else
        {
            rez[i]=b-a+1-nrvalues(mn,a,b);
        }
    }
    afisare();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct f{
    int pos,nr;
}v[100005];
int n,gcd[400005],arb[400005],t,a,b,ch,mn,d,rez[100005],val,nrm[100005],k=1;
string s;
vector<int> vct[100005];

int MIN(int x,int y)
{
    if(!x || !y) return max(x,y);
    return min(x,y);
}

int GCD(int x,int y)
{
    if(!x || !y) return max(x,y);
    int r=x%y;
    while(r)
    {
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}

void updategcd(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        gcd[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updategcd(nod*2,lt,md,pos);
    else updategcd(nod*2+1,md+1,rt,pos);

    gcd[nod]=GCD(gcd[nod*2],gcd[nod*2+1]);
}

void updatemin(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        arb[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updatemin(nod*2,lt,md,pos);
    else updatemin(nod*2+1,md+1,rt,pos);

    arb[nod]=MIN(arb[nod*2],arb[nod*2+1]);
}

void query(int nod,int lt,int rt,int x,int y)
{
    if(x<=lt && rt<=y)
    {
        mn=MIN(mn,arb[nod]);
        d=GCD(d,gcd[nod]);
        return;
    }
    if(lt==rt) return;
    int md=(lt+rt)/2;
    if(md>=x) query(nod*2,lt,md,x,y);
    if(md<y) query(nod*2+1,md+1,rt,x,y);
}

int nextint()
{
    int num=0;
    while(s[ch]==' ') ++ch;
    while(s[ch]>='0' && s[ch]<='9')
    {
        num=num*10+s[ch]-'0';
        ++ch;
    }
    return num;
}

bool comp(f x, f y)
{
    if(x.nr==y.nr) return(x.pos<y.pos);
    return(x.nr<y.nr);
}

void normalizare()
{
    sort(v+1,v+n+1,comp);
    int p=0,l=v[1].nr;
    nrm[1]=l;
    while(p<n)
    {
        ++p;
        if(l==v[p].nr) vct[k].push_back(v[p].pos);
        else
        {
            l=v[p].nr;
            ++k;
            nrm[k]=l;
            vct[k].push_back(v[p].pos);
        }
    }
}

int nrvalues(int mn,int u,int w)
{
    //seach position for x in normalization
    int md,pos,up,lw,lt,rt;
    lt=1; rt=k+1;
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(mn<nrm[md]) rt=md;
        else lt=md;
    }
    pos=lt;
    md=0;
    for(int i=0;i<=vct[pos].size();++i)
    {
        if(vct[pos][i]>=u && vct[pos][i]<=w) ++md;
    }

    return md;
}

void afisare()
{
    for(int i=1;i<=t;++i)
    {
        cout<<rez[i]<<'\n';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    getline(cin,s); n=nextint();
    getline(cin,s); ch=0;
    for(int i=1;i<=n;++i)
    {
        val=nextint();
        v[i].nr=val;
        v[i].pos=i;
        updategcd(1,1,n,i);
        updatemin(1,1,n,i);
    }

    normalizare();

    getline(cin,s); ch=0; t=nextint();
    for(int i=1;i<=t;++i)
    {
        getline(cin,s); ch=0;
        a=nextint(); b=nextint();
        mn=d=0;
        query(1,1,n,a,b);
        if(mn!=d) rez[i]=b-a+1;
        else
        {
            rez[i]=b-a+1-nrvalues(mn,a,b);
        }
    }
    afisare();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct f{
    int pos,nr;
}v[100005];
int n,gcd[400005],arb[400005],t,a,b,ch,mn,d,rez[100005],val,nrm[100005],k=1,init[100005];
string s;
vector<int> vct[100005];

int MIN(int x,int y)
{
    if(!x || !y) return max(x,y);
    return min(x,y);
}

int GCD(int x,int y)
{
    if(!x || !y) return max(x,y);
    int r=x%y;
    while(r)
    {
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}

void updategcd(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        gcd[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updategcd(nod*2,lt,md,pos);
    else updategcd(nod*2+1,md+1,rt,pos);

    gcd[nod]=GCD(gcd[nod*2],gcd[nod*2+1]);
}

void updatemin(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        arb[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updatemin(nod*2,lt,md,pos);
    else updatemin(nod*2+1,md+1,rt,pos);

    arb[nod]=MIN(arb[nod*2],arb[nod*2+1]);
}

void query(int nod,int lt,int rt,int x,int y)
{
    if(x<=lt && rt<=y)
    {
        mn=MIN(mn,arb[nod]);
        d=GCD(d,gcd[nod]);
        return;
    }
    if(lt==rt) return;
    int md=(lt+rt)/2;
    if(md>=x) query(nod*2,lt,md,x,y);
    if(md<y) query(nod*2+1,md+1,rt,x,y);
}

int nextint()
{
    int num=0;
    while(s[ch]==' ') ++ch;
    while(s[ch]>='0' && s[ch]<='9')
    {
        num=num*10+s[ch]-'0';
        ++ch;
    }
    return num;
}

bool comp(f x, f y)
{
    if(x.nr==y.nr) return(x.pos<y.pos);
    return(x.nr<y.nr);
}

void normalizare()
{
    sort(v+1,v+n+1,comp);
    int p=0,l=v[1].nr;
    nrm[1]=l;
    while(p<n)
    {
        ++p;
        if(l==v[p].nr) vct[k].push_back(v[p].pos);
        else
        {
            l=v[p].nr;
            ++k;
            nrm[k]=l;
            vct[k].push_back(v[p].pos);
        }
    }
}

int nrvalues(int mn,int u,int w)
{
    //seach position for x in normalization
    int md,pos,lt,rt,up,lw;
    lt=1; rt=k+1;
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(mn<nrm[md]) rt=md;
        else lt=md;
    }
    pos=lt;
    md=0;
    //lower bound
    lt=0; rt=vct[pos].size();
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(vct[pos][md]<u) lt=md;
        else rt=md;
    }
    lw=rt;
    if(lw>=vct[pos].size() || vct[pos][lw-1]>=u) --lw;
    //upper bound
    lt=0; rt=vct[pos].size();
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(vct[pos][md]<=w) lt=md;
        else rt=md;
    }
    up=lt;
    return(up-lw+1);
}

void afisare()
{
    for(int i=1;i<=t;++i)
    {
        cout<<rez[i]<<'\n';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    getline(cin,s); n=nextint();
    getline(cin,s); ch=0;
    for(int i=1;i<=n;++i)
    {
        val=nextint();
        init[i]=val;
        v[i].nr=val;
        v[i].pos=i;
        updategcd(1,1,n,i);
        updatemin(1,1,n,i);
    }

    normalizare();

    getline(cin,s); ch=0; t=nextint();
    for(int i=1;i<=t;++i)
    {
        getline(cin,s); ch=0;
        a=nextint(); b=nextint();
        mn=d=0;
        query(1,1,n,a,b);
        if(mn!=d) rez[i]=b-a+1;
        else
        {
            rez[i]=b-a+1-nrvalues(mn,a,b);
        }
    }
    afisare();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct f{
    int pos,nr;
}v[100005];
int n,gcd[400005],arb[400005],t,a,b,ch,mn,d,rez[100005],val,nrm[100005],k=1,init[100005];
string s;
vector<int> vct[100005];

int MIN(int x,int y)
{
    if(!x || !y) return max(x,y);
    return min(x,y);
}

int GCD(int x,int y)
{
    if(!x || !y) return max(x,y);
    int r=x%y;
    while(r)
    {
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}

void updategcd(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        gcd[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updategcd(nod*2,lt,md,pos);
    else updategcd(nod*2+1,md+1,rt,pos);

    gcd[nod]=GCD(gcd[nod*2],gcd[nod*2+1]);
}

void updatemin(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        arb[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updatemin(nod*2,lt,md,pos);
    else updatemin(nod*2+1,md+1,rt,pos);

    arb[nod]=MIN(arb[nod*2],arb[nod*2+1]);
}

void query(int nod,int lt,int rt,int x,int y)
{
    if(x<=lt && rt<=y)
    {
        mn=MIN(mn,arb[nod]);
        d=GCD(d,gcd[nod]);
        return;
    }
    if(lt==rt) return;
    int md=(lt+rt)/2;
    if(md>=x) query(nod*2,lt,md,x,y);
    if(md<y) query(nod*2+1,md+1,rt,x,y);
}

int nextint()
{
    int num=0;
    while(s[ch]==' ') ++ch;
    while(s[ch]>='0' && s[ch]<='9')
    {
        num=num*10+s[ch]-'0';
        ++ch;
    }
    return num;
}

bool comp(f x, f y)
{
    if(x.nr==y.nr) return(x.pos<y.pos);
    return(x.nr<y.nr);
}

void normalizare()
{
    sort(v+1,v+n+1,comp);
    int p=0,l=v[1].nr;
    nrm[1]=l;
    while(p<n)
    {
        ++p;
        if(l==v[p].nr) vct[k].push_back(v[p].pos);
        else
        {
            l=v[p].nr;
            ++k;
            nrm[k]=l;
            vct[k].push_back(v[p].pos);
        }
    }
}

int nrvalues(int mn,int u,int w)
{
    //seach position for x in normalization
    int md,pos,lt,rt;
    lt=1; rt=k+1;
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(mn<nrm[md]) rt=md;
        else lt=md;
    }
    pos=lt;
    md=0;
    for(int i=0;i<vct[pos].size();++i)
    {
        if(vct[pos][i]>=u && vct[pos][i]<=w) ++md;
    }

    return md;
}

void afisare()
{
    for(int i=1;i<=t;++i)
    {
        cout<<rez[i]<<'\n';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    getline(cin,s); n=nextint();
    getline(cin,s); ch=0;
    for(int i=1;i<=n;++i)
    {
        val=nextint();
        init[i]=val;
        v[i].nr=val;
        v[i].pos=i;
        updategcd(1,1,n,i);
        updatemin(1,1,n,i);
    }

    normalizare();

    getline(cin,s); ch=0; t=nextint();
    for(int i=1;i<=t;++i)
    {
        getline(cin,s); ch=0;
        a=nextint(); b=nextint();
        mn=d=0;
        query(1,1,n,a,b);
        if(mn!=d) rez[i]=b-a+1;
        else
        {
            rez[i]=b-a+1-nrvalues(mn,a,b);
        }
    }
    afisare();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct f{
    int pos,nr;
}v[100005];
int n,gcd[400005],arb[400005],t,a,b,ch,mn,d,rez[100005],val,nrm[100005],k=1;
string s;
vector<int> vct[100005];

int MIN(int x,int y)
{
    if(!x || !y) return max(x,y);
    return min(x,y);
}

int GCD(int x,int y)
{
    if(!x || !y) return max(x,y);
    int r=x%y;
    while(r)
    {
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}

void updategcd(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        gcd[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updategcd(nod*2,lt,md,pos);
    else updategcd(nod*2+1,md+1,rt,pos);

    gcd[nod]=GCD(gcd[nod*2],gcd[nod*2+1]);
}

void updatemin(int nod,int lt,int rt,int pos)
{
    if(lt==rt)
    {
        arb[nod]=val;
        return;
    }
    int md=(lt+rt)/2;
    if(pos<=md) updatemin(nod*2,lt,md,pos);
    else updatemin(nod*2+1,md+1,rt,pos);

    arb[nod]=MIN(arb[nod*2],arb[nod*2+1]);
}

void query(int nod,int lt,int rt,int x,int y)
{
    if(x<=lt && rt<=y)
    {
        mn=MIN(mn,arb[nod]);
        d=GCD(d,gcd[nod]);
        return;
    }
    if(lt==rt) return;
    int md=(lt+rt)/2;
    if(md>=x) query(nod*2,lt,md,x,y);
    if(md<y) query(nod*2+1,md+1,rt,x,y);
}

int nextint()
{
    int num=0;
    while(s[ch]==' ') ++ch;
    while(s[ch]>='0' && s[ch]<='9')
    {
        num=num*10+s[ch]-'0';
        ++ch;
    }
    return num;
}

bool comp(f x, f y)
{
    if(x.nr==y.nr) return(x.pos<y.pos);
    return(x.nr<y.nr);
}

void normalizare()
{
    sort(v+1,v+n+1,comp);
    int p=0,l=v[1].nr;
    nrm[1]=l;
    while(p<n)
    {
        ++p;
        if(l==v[p].nr) vct[k].push_back(v[p].pos);
        else
        {
            l=v[p].nr;
            ++k;
            nrm[k]=l;
            vct[k].push_back(v[p].pos);
        }
    }
}

int nrvalues(int mn,int u,int w)
{
    //seach position for x in normalization
    int md,pos,up,lw,lt,rt;
    lt=1; rt=k+1;
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(mn<nrm[md]) rt=md;
        else lt=md;
    }
    pos=lt;
    //lower bound in vct[pos]
    lt=0; rt=vct[pos].size();
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(u<vct[pos][md]) rt=md;
        else lt=md;
    }
    lw=lt;
    while(vct[pos][lw]<u) ++lw;
    //upper bound
    lt=0; rt=vct[pos].size();
    while(rt-lt!=1)
    {
        md=(lt+rt)/2;
        if(w<=vct[pos][md]) lt=md;
        else rt=md;
    }
    up=lt;
    return (up-lw+1);
}

void afisare()
{
    for(int i=1;i<=t;++i)
    {
        cout<<rez[i]<<'\n';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    getline(cin,s); n=nextint();
    getline(cin,s); ch=0;
    for(int i=1;i<=n;++i)
    {
        val=nextint();
        v[i].nr=val;
        v[i].pos=i;
        updategcd(1,1,n,i);
        updatemin(1,1,n,i);
    }

    normalizare();

    getline(cin,s); ch=0; t=nextint();
    for(int i=1;i<=t;++i)
    {
        getline(cin,s); ch=0;
        a=nextint(); b=nextint();
        mn=d=0;
        query(1,1,n,a,b);
        if(mn!=d) rez[i]=b-a+1;
        else
        {
            rez[i]=b-a+1-nrvalues(mn,a,b);
        }
    }
    afisare();
    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <cstring>
#include <set>

#define forn(i,n) for(int i = 0; i < (int)(n); i++)
#define forsn(i,s,n) for(int i = (int)(s); i < (int)(n); i++)
#define dforn(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define all(v) ((v).begin, (v).end)
#define pb push_back
#define x first
#define y second
#define mp make_pair

using namespace std;

typedef pair<int,int> par;

int n,t,k;
int l,r;
int s[100100];
int m[100100][20];
int rmq[100100][20];
int countmin[100100][20];

int mcd(int a, int b)
{
	if(b == 0) return a;

	return mcd(b, a % b);
}

void ini()
{
	forn(i,n) m[i][0] = s[i];

	for(int j = 1; (1<<j) < n; j++)
	{
		for(int i = 0; i + (1 << j) <= n; i++)
		{
			m[i][j] = mcd(m[i][j-1], m[i+(1<<(j-1))][j-1]);
		}
	}

	forn(i,n) { rmq[i][0] = i; countmin[i][0] = 1; }

	for(int j = 1; (1<<j) < n; j++)
	{
		for(int i = 0; i + (1 << j) <= n; i++)
		{
			int p1,p2;
			p1 = rmq[i][j-1]; p2 = rmq[i+(1<<(j-1))][j-1];
			if(s[p1] != s[p2])
			{
				if(s[p1] < s[p2])
				{
					rmq[i][j] = p1;
					countmin[i][j] = countmin[i][j-1];
				}
				else
				{
					rmq[i][j] = p2;
					countmin[i][j] = countmin[i+(1<<(j-1))][j-1];
				}
			}
			else{
				rmq[i][j] = p1;
				countmin[i][j] = countmin[i][j-1] + countmin[i+(1<<(j-1))][j-1];
			}
		}
	}
}

int main()
{
	//freopen("test.txt", "r", stdin);
	cin >> n;
	forn(i,n) cin >> s[i];
	ini();
	cin >> t;
	forn(caso,t)
	{
		cin >> l >> r;
		l--;r--;
		dforn(i,20)
		{
			if( (1 << i) <= (r-l+1) )
			{
				k = i;
				break;
			}
		}
		//cout << k << " " << m[l][k] << " " << m[r - (1<<k) + 1][k] << endl;
		int g = mcd(m[l][k], m[r - (1<<k) + 1][k]);
		int save = 0;
		int acum = l;

		//cout << g << " " << min(s[ rmq[l][k] ], s[ rmq[r - (1<<k) + 1][k] ]) << endl;

		forn(i,k+1)
		{
			if( g == s[ rmq[acum][i] ] and ( (1<<i) & (r-l+1) ) )
			{
				save += countmin[acum][i];
				acum += (1<<i);
				//cout << acum << " " << save << endl;
			}
		}

		cout << (r-l+1-save) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <cstring>
#include <set>

#define forn(i,n) for(int i = 0; i < (int)(n); i++)
#define forsn(i,s,n) for(int i = (int)(s); i < (int)(n); i++)
#define dforn(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define all(v) ((v).begin, (v).end)
#define pb push_back
#define x first
#define y second
#define mp make_pair

using namespace std;

typedef pair<int,int> par;

int n,t,k;
int l,r;
int s[100100];
int m[100100][20];
int rmq[100100][20];
int countmin[100100][20];

int mcd(int a, int b)
{
	if(b == 0) return a;

	return mcd(b, a % b);
}

void ini()
{
	forn(i,n) m[i][0] = s[i];

	for(int j = 1; (1<<j) <= n; j++)
	{
		for(int i = 0; i + (1 << j) <= n; i++)
		{
			m[i][j] = mcd(m[i][j-1], m[i+(1<<(j-1))][j-1]);
		}
	}

	forn(i,n) { rmq[i][0] = i; countmin[i][0] = 1; }

	for(int j = 1; (1<<j) <= n; j++)
	{
		for(int i = 0; i + (1 << j) <= n; i++)
		{
			int p1,p2;
			p1 = rmq[i][j-1]; p2 = rmq[i+(1<<(j-1))][j-1];
			if(s[p1] != s[p2])
			{
				if(s[p1] < s[p2])
				{
					rmq[i][j] = p1;
					countmin[i][j] = countmin[i][j-1];
				}
				else
				{
					rmq[i][j] = p2;
					countmin[i][j] = countmin[i+(1<<(j-1))][j-1];
				}
			}
			else{
				rmq[i][j] = p1;
				countmin[i][j] = countmin[i][j-1] + countmin[i+(1<<(j-1))][j-1];
			}
		}
	}
}

int main()
{
	//freopen("test.txt", "r", stdin);
	cin >> n;
	forn(i,n) cin >> s[i];
	ini();
	cin >> t;
	forn(caso,t)
	{
		cin >> l >> r;
		l--;r--;
		dforn(i,20)
		{
			if( (1 << i) <= (r-l+1) )
			{
				k = i;
				break;
			}
		}
		//cout << k << " " << m[l][k] << " " << m[r - (1<<k) + 1][k] << endl;
		int g = mcd(m[l][k], m[r - (1<<k) + 1][k]);
		int save = 0;
		int acum = l;

		//cout << g << " " << min(s[ rmq[l][k] ], s[ rmq[r - (1<<k) + 1][k] ]) << endl;

		forn(i,k+1)
		{
			if( (acum + (1<<i) <= n) and g == s[ rmq[acum][i] ] and ( (1<<i) & (r-l+1) ) )
			{
				save += countmin[acum][i];
				acum += (1<<i);
				//cout << acum << " " << save << endl;
			}
		}

		cout << (r-l+1-save) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <cstring>
#include <set>

#define forn(i,n) for(int i = 0; i < (int)(n); i++)
#define forsn(i,s,n) for(int i = (int)(s); i < (int)(n); i++)
#define dforn(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define all(v) ((v).begin, (v).end)
#define pb push_back
#define x first
#define y second
#define mp make_pair

using namespace std;

typedef pair<int,int> par;

int n,t,k;
int l,r;
int s[100100];
int m[100100][20];
int rmq[100100][20];
int countmin[100100][20];

int mcd(int a, int b)
{
	if(b == 0) return a;

	return mcd(b, a % b);
}

void ini()
{
	forn(i,n) m[i][0] = s[i];

	for(int j = 1; (1<<j) < n; j++)
	{
		for(int i = 0; i + (1 << j) <= n; i++)
		{
			m[i][j] = mcd(m[i][j-1], m[i+(1<<(j-1))][j-1]);
		}
	}

	forn(i,n) { rmq[i][0] = i; countmin[i][0] = 1; }

	for(int j = 1; (1<<j) < n; j++)
	{
		for(int i = 0; i + (1 << j) <= n; i++)
		{
			int p1,p2;
			p1 = rmq[i][j-1]; p2 = rmq[i+(1<<(j-1))][j-1];
			if(s[p1] != s[p2])
			{
				if(s[p1] < s[p2])
				{
					rmq[i][j] = p1;
					countmin[i][j] = countmin[i][j-1];
				}
				else
				{
					rmq[i][j] = p2;
					countmin[i][j] = countmin[i+(1<<(j-1))][j-1];
				}
			}
			else{
				rmq[i][j] = p1;
				countmin[i][j] = countmin[i][j-1] + countmin[i+(1<<(j-1))][j-1];
			}
		}
	}
}

int main()
{
	//freopen("test.txt", "r", stdin);
	cin >> n;
	forn(i,n) cin >> s[i];
	ini();
	cin >> t;
	forn(caso,t)
	{
		cin >> l >> r;
		l--;r--;
		dforn(i,20)
		{
			if( (1 << i) <= (r-l+1) )
			{
				k = i;
				break;
			}
		}
		//cout << k << " " << m[l][k] << " " << m[r - (1<<k) + 1][k] << endl;
		int g = mcd(m[l][k], m[r - (1<<k) + 1][k]);
		int save = 0;
		int acum = l;

		//cout << g << " " << min(s[ rmq[l][k] ], s[ rmq[r - (1<<k) + 1][k] ]) << endl;
		int add = 1 - ( (1 << k) == (r-l+1));
		forn(i,k+add)
		{
			if( g == s[ rmq[acum][i] ] and ( (1<<i) & (r-l+1) ) )
			{
				save += countmin[acum][i];
				acum += (1<<i);
				//cout << acum << " " << save << endl;
			}
		}

		cout << (r-l+1-save) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <cstring>
#include <set>

#define forn(i,n) for(int i = 0; i < (int)(n); i++)
#define forsn(i,s,n) for(int i = (int)(s); i < (int)(n); i++)
#define dforn(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define all(v) ((v).begin, (v).end)
#define pb push_back
#define x first
#define y second
#define mp make_pair

using namespace std;

typedef pair<int,int> par;

int n,t,k;
int l,r;
int s[100100];
int m[100100][20];
int rmq[100100][20];
int countmin[100100][20];

int mcd(int a, int b)
{
	if(b == 0) return a;

	return mcd(b, a % b);
}

void ini()
{
	forn(i,n) m[i][0] = s[i];

	for(int j = 1; (1<<j) <= n; j++)
	{
		for(int i = 0; i + (1 << j) <= n; i++)
		{
			m[i][j] = mcd(m[i][j-1], m[i+(1<<(j-1))][j-1]);
		}
	}

	forn(i,n) { rmq[i][0] = i; countmin[i][0] = 1; }

	for(int j = 1; (1<<j) <= n; j++)
	{
		for(int i = 0; i + (1 << j) <= n; i++)
		{
			int p1,p2;
			p1 = rmq[i][j-1]; p2 = rmq[i+(1<<(j-1))][j-1];
			if(s[p1] != s[p2])
			{
				if(s[p1] < s[p2])
				{
					rmq[i][j] = p1;
					countmin[i][j] = countmin[i][j-1];
				}
				else
				{
					rmq[i][j] = p2;
					countmin[i][j] = countmin[i+(1<<(j-1))][j-1];
				}
			}
			else{
				rmq[i][j] = p1;
				countmin[i][j] = countmin[i][j-1] + countmin[i+(1<<(j-1))][j-1];
			}
		}
	}
}

int main()
{
	//freopen("test.txt", "r", stdin);
	cin >> n;
	forn(i,n) cin >> s[i];
	ini();

	cin >> t;

	forn(caso,t)
	{
		cin >> l >> r;
		l--;r--;
		dforn(i,20)
		{
			if( (1 << i) <= (r-l+1) )
			{
				k = i;
				break;
			}
		}
		//cout << k << " " << m[l][k] << " " << m[r - (1<<k) + 1][k] << endl;
		int g = mcd(m[l][k], m[r - (1<<k) + 1][k]);
		int save = 0;
		int acum = l;

		//cout << g << " " << min(s[ rmq[l][k] ], s[ rmq[r - (1<<k) + 1][k] ]) << endl;

		forn(i,k+1)
		{
			if( (1<<i) & (r-l+1) )
			{
				//cout << acum << " min " << s[ rmq[acum][i] ] << endl;
				if( (acum + (1<<i) <= n) and g == s[ rmq[acum][i] ] )
				{
					save += countmin[acum][i];
					//cout << acum << " "  << (acum+(1<<i)-1) << " " << countmin[acum][i] << endl;
				}
				acum += (1<<i);
			}
		}

		cout << (r-l+1-save) << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e6+10;

pair<long int, long int> tree[mx*4];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0){
                ants=tree[r].second;
                currgcd=tree[r].first;
                }
            else {
                ants = 0;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        if(flag)ants=0;
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


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

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1){
        ants=0;
        return;
    }
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants+=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first%currgcd==0&&tree[r].second!=0){
                ants+=tree[r].second;
                currgcd=min(currgcd,tree[r].first);
            }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        if(flag)ants=0;
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define mp make_pair

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first%tree[2*r].first==0)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first%tree[2*r+1].first==0)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1)
        return;
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants+=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first%currgcd==0)
                ants+=tree[r].second;
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx*4];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag==1)
        return;
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0){
                ants=tree[r].second;
                currgcd=min(currgcd,tree[r].first);
                }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1){
        ants=0;
        return;
    }
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(currgcd%tree[r].first==0&&tree[r].second){
                ants=tree[r].second;
                currgcd=tree[r].first;
                }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        if(flag)ants=0;
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0){
                ants=tree[r].second;
                currgcd=tree[r].first;
                }
            else {
                ants = 0;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        if(flag)ants=0;
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx*4];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0){
                ants=tree[r].second;
                currgcd=tree[r].first;
                }
            else {
                ants = 0;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


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

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1)
        return;
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants+=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first%currgcd==0&&tree[r].second!=0){
                ants+=tree[r].second;
                currgcd=tree[r].first;
            }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx*4];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0){
                ants=tree[r].second;
                }
            else {
                ants = 0;
            }
            currgcd=min(currgcd,tree[r].first);
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx*4];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0){
                ants=tree[r].second;
                currgcd=min(currgcd,tree[r].first);
                }
            else {
                ants = 0;
                currgcd=min(currgcd,tree[r].first);
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1){
        ants=0;
        return;
    }
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0&&tree[r].second){
                ants=tree[r].second;
                currgcd=tree[r].first;
                }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        if(flag)ants=0;
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e6+10;

pair<long int, long int> tree[mx*4];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0){
                ants=tree[r].second;
                }
            else {
                ants = 0;
            }
            currgcd=__gcd(currgcd,tree[r].first);
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        if(flag)ants=0;
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define mp make_pair

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1)
        return;
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants+=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first%currgcd==0)
                ants+=tree[r].second;
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


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

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1){
        ants=0;
        return;
    }
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].second!=0){
                if(tree[r].first==currgcd)
                    ants+=tree[r].second;
                else if(currgcd%tree[r].first==0)
                    ants=tree[r].first;
                currgcd=min(currgcd,tree[r].first);
            }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        if(flag)ants=0;
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx*4];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag==1)
        return;
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0){
                ants=tree[r].second;
                currgcd=min(currgcd,tree[r].first);
                }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1){
        ants=0;
        return;
    }
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].second!=0){
                if(tree[r].first==currgcd)
                    ants+=tree[r].second;
                else if(currgcd%tree[r].first==0){
                    ants=tree[r].second;
                    currgcd=tree[r].first;
                }
                else if (currgcd%tree[r].first){
                    ants=0;
                    flag=1;
                }
            }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        if(flag)ants=0;
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <iostream>
#define mp make_pair

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1)
        return;
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants+=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first%currgcd==0&&tree[r].second!=0){
                ants+=tree[r].second;
                currgcd=tree[r].first;
            }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


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

const int mx = 1e5+10;

pair<long int, long int> tree[mx];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(flag ==1){
        ants=0;
        return;
    }
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].second!=0){
                if(tree[r].first==currgcd)
                    ants+=tree[r].second;
                else if(currgcd%tree[r].first==0)
                    ants=tree[r].second;
                currgcd=min(currgcd,tree[r].first);
            }
            else {
                ants = 0;
                flag = 1;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;flag=0;
        qu(1, n, 1);
        if(flag)ants=0;
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+10;

pair<long int, long int> tree[mx*4];
long int a[mx],currgcd,ants,flag;
int qs,qe,n,q;

void build(int x, int y, int r){
    if(x==y){
        tree[r].first=a[x];
        tree[r].second=1;
        return;
    }
    int mid = (x+y)>>1;
    build(x, mid, 2*r);build(mid+1,y,2*r+1);
    tree[r].first=__gcd(tree[2*r].first,tree[2*r+1].first);
    if(tree[r].first==tree[2*r].first)
        tree[r].second+=tree[2*r].second;
    if(tree[r].first==tree[2*r+1].first)
        tree[r].second+=tree[2*r+1].second;
}

void qu(int x, int y , int r){
    if(qs>y||qe<x||x>y)
        return;
    if(qs<=x && qe>=y){
        if(currgcd==0){
            ants=tree[r].second;
            currgcd=tree[r].first;
        }
        else if (currgcd){
            if(tree[r].first==currgcd)
                ants+=tree[r].second;
            else if(tree[r].first%currgcd==0)
                    ants=ants;
            else if(currgcd%tree[r].first==0){
                ants=tree[r].second;
                currgcd=min(currgcd,tree[r].first);
                }
            else {
                ants = 0;
            }
        }
        return;
    }
    int mid=(x+y)>>1;
    qu(x, mid, 2*r);qu(mid+1, y, 2*r+1);
}

int main()
{   cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    build(1, n, 1);
    cin >> q;
    for(int i =1;i<=q;i++){
        cin >> qs >> qe;
        ants=0;currgcd=0;
        qu(1, n, 1);
        cout << (qe-qs+1)-ants<<endl;
    }
    return 0;
}


#pragma comment(linker, "/STACK:64777216")
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#include<sstream>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<memory.h>
#include<ctime>
#include<cassert>

#define pb push_back
#define sz(a) (int)a.size()
#define bs binary_search
#define np next_permutation
#define mp make_pair
#define all(a) a.begin(),a.end()
#define read(a) scanf("%d", &a)
#define writeln(a) printf("%d\n", a);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forv(i, v) for (int i = 0; i < sz(v); ++i)
#define _(a, b) memset(a, b, sizeof a)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

template<class T> inline T sqr(T x) { return x * x; }

const double pi = acos(-1.0), eps = 1e-9;
const int INF = 1000 * 1000 * 1000, MAXN = 100005, MOD = 1000000007;
const ll INFL = 1e+18;

void prepare(string s) {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w",stdout);
#else
    if (sz(s) != 0) {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
#endif
}

int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a;
}

struct SegmentTree {
    pair<int, int> tmin[4*MAXN];
    int tgcd[4*MAXN];

    pair<int, int> combine (pair<int, int> a, pair<int, int> b) {
        if (a.first < b.first)
        return a;
        if (b.first < a.first)
            return b;
        return mp(a.first, a.second + b.second);
    }

    void build (int *a, int v, int L, int R) {
        if (L == R) {
            tmin[v] = mp(a[L], 1);
            tgcd[v] = a[L];
        }
        else {
            int M = (L + R) / 2;
            build(a, v * 2, L, M);
            build(a, v * 2 + 1, M + 1, R);
            tmin[v] = combine(tmin[v*2], tmin[v*2+1]);
            tgcd[v] = gcd(tgcd[v*2], tgcd[v*2+1]);
        }
    }

    pair<int, int> get_min (int v, int L, int R, int l, int r) {
        if (l > r)
            return mp(INF, 0);
        if (l == L && r == R)
            return tmin[v];
        int M = (L + R) / 2;
        return combine(get_min(v * 2, L, M, l, min(M, r)),
            get_min(v * 2 + 1, M + 1, R, max(l, M + 1), r));
    }

    int get_gcd (int v, int L, int R, int l, int r) {
        if (l > r)
            return 0;
        if (l == L && r == R)
            return tgcd[v];
        int M = (L + R) / 2;
        return gcd(get_gcd(v * 2, L, M, l, min(M, r)),
            get_gcd(v * 2 + 1, M + 1, R, max(l, M + 1), r));
    }
};

SegmentTree T;
int n, a[MAXN], q;

void solve()
{
    cin >> n;
    forn (i, n) cin >> a[i];
    T.build(a, 1, 0, n - 1);
    cin >> q;
    while (q) {
        --q;
        int l, r;
        cin >> l >> r;
        --l; --r;
        pair<int, int> Min = T.get_min(1, 0, n - 1, l, r);
        int Gcd = T.get_gcd(1, 0, n - 1, l, r);
        if (Min.first == Gcd)
            cout << r - l + 1 - Min.second << '\n';
        else
            cout << r - l + 1 << '\n';
    }
}

int main()
{
    prepare("");

    solve();

    return 0;
}


#pragma comment(linker, "/STACK:64777216")
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#include<sstream>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<memory.h>
#include<ctime>
#include<cassert>

#define pb push_back
#define sz(a) (int)a.size()
#define bs binary_search
#define np next_permutation
#define mp make_pair
#define all(a) a.begin(),a.end()
#define read(a) scanf("%d", &a)
#define writeln(a) printf("%d\n", a);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forv(i, v) for (int i = 0; i < sz(v); ++i)
#define _(a, b) memset(a, b, sizeof a)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

template<class T> inline T sqr(T x) { return x * x; }

const double pi = acos(-1.0), eps = 1e-9;
const int INF = 1000 * 1000 * 1000, MAXN = 100005, MOD = 1000000007;
const ll INFL = 1e+18;

void prepare(string s) {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w",stdout);
#else
    if (sz(s) != 0) {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
#endif
}

int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a;
}

struct SegmentTree {
    pair<int, int> tmin[4*MAXN];
    int tgcd[4*MAXN];

    pair<int, int> combine (pair<int, int> a, pair<int, int> b) {
        if (a.first < b.first)
        return a;
        if (b.first < a.first)
            return b;
        return mp(a.first, a.second + b.second);
    }

    void build (int *a, int v, int L, int R) {
        if (L == R) {
            tmin[v] = mp(a[L], 1);
            tgcd[v] = a[L];
        }
        else {
            int M = (L + R) / 2;
            build(a, v * 2, L, M);
            build(a, v * 2 + 1, M + 1, R);
            tmin[v] = combine(tmin[v*2], tmin[v*2+1]);
            tgcd[v] = gcd(tgcd[v*2], tgcd[v*2+1]);
        }
    }

    pair<int, int> get_min (int v, int L, int R, int l, int r) {
        if (l > r)
            return mp(INF, 0);
        if (l == L && r == R)
            return tmin[v];
        int M = (L + R) / 2;
        return combine(get_min(v * 2, L, M, l, min(M, r)),
            get_min(v * 2 + 1, M + 1, R, max(l, M + 1), r));
    }

    int get_gcd (int v, int L, int R, int l, int r) {
        if (l > r)
            return 0;
        if (l == L && r == R)
            return tgcd[v];
        int M = (L + R) / 2;
        return gcd(get_gcd(v * 2, L, M, l, min(M, r)),
            get_gcd(v * 2 + 1, M + 1, R, max(l, M + 1), r));
    }
};

SegmentTree T;
int n, a[MAXN], q;

void solve()
{
    cin >> n;
    forn (i, n) scanf("%d", &a[i]);
    T.build(a, 1, 0, n - 1);
    cin >> q;
    while (q) {
        --q;
        int l, r;
        cin >> l >> r;
        --l; --r;
        pair<int, int> Min = T.get_min(1, 0, n - 1, l, r);
        int Gcd = T.get_gcd(1, 0, n - 1, l, r);
        if (Min.first == Gcd)
           // cout << r - l + 1 - Min.second << '\n';
			   printf("%d\n", r - l + 1 - Min.second);
        else
           // cout << r - l + 1 << '\n';
		   printf("%d\n", r - l + 1);
    }
}

int main()
{
    prepare("");

    solve();

    return 0;
}


#pragma comment(linker, "/STACK:64777216")
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#include<sstream>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<memory.h>
#include<ctime>
#include<cassert>

#define pb push_back
#define sz(a) (int)a.size()
#define bs binary_search
#define np next_permutation
#define mp make_pair
#define all(a) a.begin(),a.end()
#define read(a) scanf("%d", &a)
#define writeln(a) printf("%d\n", a);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forv(i, v) for (int i = 0; i < sz(v); ++i)
#define _(a, b) memset(a, b, sizeof a)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

template<class T> inline T sqr(T x) { return x * x; }

const double pi = acos(-1.0), eps = 1e-9;
const int INF = 1000 * 1000 * 1000, MAXN = 100005, MOD = 1000000007;
const ll INFL = 1e+18;

void prepare(string s) {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w",stdout);
#else
    if (sz(s) != 0) {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
#endif
}

struct Point {
    ll x, y, cx, cy;
    void scan () {cin >> x >> y >> cx >> cy;}
    void turn () {
        x -= cx;
        y -= cy;
        int tmp = x;
        x = -y;
        y = tmp;
        x += cx;
        y += cy;
    }
    Point () {
        x = y = cx = cy = 0;
    }
    bool operator < (const Point a) const {
        return x < a.x || x == a.x && y < a.y;
    }
};

int n, mask[10];
vector<Point> a;

ll dist (Point a, Point b) {
    return sqr(a.x - b.x) + sqr(a.y - b.y);
}

bool check (vector<Point> a) {
    set<Point> t;
    sort(all(a));
    forv (i, a) t.insert(a[i]);
    return dist(a[0], a[3]) == dist(a[1], a[2]) && dist(a[0], a[1]) == dist(a[1], a[3]) && dist(a[1], a[3]) == dist(a[3], a[2]) && dist(a[3], a[2]) == dist(a[2], a[0]) && dist(a[2], a[0]) == dist(a[0], a[1]) && sz(t) == 4;
}

void solve()
{
    cin >> n;
    forn (i, n) {
        a.resize(4);
        forn (p, 4) a[p].scan();
        vector<Point> tmp = a;
        _(mask, 0);
        if (check(tmp))
            cout << 0 << '\n';
        else {
            int Min = INF;
            for (int j = 0; j < 256; j++) {
                tmp = a;
                for (int k = 3; k >= 0; k--)
                    if (mask[k] < 3) {
                        mask[k]++;
                        break;
                    }
                    else
                        mask[k] = 0;
                forn (j, 4)
                    forn (k, mask[j])
                        tmp[j].turn();
                if (check(tmp))
                    Min = min(Min, mask[0] + mask[1] + mask[2] + mask[3]);
            }
            if (Min != INF)
                cout << Min;
            else
                cout << -1;
            cout << '\n';
        }
    }
}

int main()
{
    prepare("");

    solve();

    return 0;
}


#pragma comment(linker, "/STACK:64777216")
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#include<sstream>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<memory.h>
#include<ctime>
#include<cassert>

#define pb push_back
#define sz(a) (int)a.size()
#define bs binary_search
#define np next_permutation
#define mp make_pair
#define all(a) a.begin(),a.end()
#define read(a) scanf("%d", &a)
#define writeln(a) printf("%d\n", a);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forv(i, v) for (int i = 0; i < sz(v); ++i)
#define _(a, b) memset(a, b, sizeof a)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

template<class T> inline T sqr(T x) { return x * x; }

const double pi = acos(-1.0), eps = 1e-9;
const int INF = 1000 * 1000 * 1000, MAXN = 100005, MOD = 1000000007;
const ll INFL = 1e+18;

void prepare(string s) {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w",stdout);
#else
    if (sz(s) != 0) {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
#endif
}

inline int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a;
}

struct SegmentTree {
    pair<int, int> tmin[4*MAXN];
    int tgcd[4*MAXN];

    pair<int, int> combine (pair<int, int> a, pair<int, int> b) {
        if (a.first < b.first)
        return a;
        if (b.first < a.first)
            return b;
        return mp(a.first, a.second + b.second);
    }

    void build (int *a, int v, int L, int R) {
        if (L == R) {
            tmin[v] = mp(a[L], 1);
            tgcd[v] = a[L];
        }
        else {
            int M = (L + R) / 2;
            build(a, v * 2, L, M);
            build(a, v * 2 + 1, M + 1, R);
            tmin[v] = combine(tmin[v*2], tmin[v*2+1]);
            tgcd[v] = gcd(tgcd[v*2], tgcd[v*2+1]);
        }
    }

    pair<int, int> get_min (int v, int L, int R, int l, int r) {
        if (l > r)
            return mp(INF, 0);
        if (l == L && r == R)
            return tmin[v];
        int M = (L + R) / 2;
        return combine(get_min(v * 2, L, M, l, min(M, r)),
            get_min(v * 2 + 1, M + 1, R, max(l, M + 1), r));
    }

    int get_gcd (int v, int L, int R, int l, int r) {
        if (l > r)
            return 0;
        if (l == L && r == R)
            return tgcd[v];
        int M = (L + R) / 2;
        return gcd(get_gcd(v * 2, L, M, l, min(M, r)),
            get_gcd(v * 2 + 1, M + 1, R, max(l, M + 1), r));
    }
};

SegmentTree T;
int n, a[MAXN], q;

void solve()
{
    cin >> n;
    forn (i, n) scanf("%d", &a[i]);
    T.build(a, 1, 0, n - 1);
    cin >> q;
    while (q) {
        --q;
        int l, r;
        cin >> l >> r;
        --l; --r;
        pair<int, int> Min = T.get_min(1, 0, n - 1, l, r);
        int Gcd = T.get_gcd(1, 0, n - 1, l, r);
        if (Min.first == Gcd)
           // cout << r - l + 1 - Min.second << '\n';
               printf("%d\n", r - l + 1 - Min.second);
        else
           // cout << r - l + 1 << '\n';
           printf("%d\n", r - l + 1);
    }
}

int main()
{
    prepare("");

    solve();

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

#define mid (lf + rg >> 1)
#define right (left | 1)
#define left (v << 1)

#define pb push_back
#define mp make_pair
#define nd second
#define st first

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

const ll linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e5 + 9;
const int kokn = sqrt(N);

int n, a[N], q, l, r, ans[N], tree[4*N], tree2[4*N];

vector < pii > temp;

pair < int, pii > Q[N];

map < int, int > hash;

bool cmp(pair < int, pii > a, pair < int, pii > b) {
	if (a.st / kokn != b.st / kokn) {
		return a.st / kokn < b.st / kokn;
	}
	return a.nd.st < b.nd.st;
}

int build(int v, int lf, int rg) {
	if (lf == rg) {
		return tree[v] = a[lf];
	}
	return tree[v] = __gcd(build(left, lf, mid), build(right, mid+1, rg));
}

int build2(int v, int lf, int rg) {
	if (lf == rg) {
		return tree2[v] = a[lf];
	}
	return tree2[v] = min(build2(left, lf, mid), build2(right, mid+1, rg));
}

int query(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return -1;
	}
	if (l <= lf and rg <= r) {
		return tree[v];
	}
	int t1 = query(left, lf, mid, l, r);
	int t2 = query(right, mid+1, rg, l, r);
	if (t1 == -1) {
		return t2;
	} else if (t2 == -1) {
		return t1;
	}
	return __gcd(t1, t2);
}

int query2(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return inf;
	}
	if (l <= lf and rg <= r) {
		return tree2[v];
	}
	int t1 = query2(left, lf, mid, l, r);
	int t2 = query2(right, mid+1, rg, l, r);
	return min(t1, t2);
}

 main() {

	scanf("%lld", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
	scanf("%lld", &q);
	build(1, 1, n);
	build2(1, 1, n);
	for (int i = 1; i <= q; i++) {
		scanf("%lld %lld", &l, &r);
		Q[i] = mp(l, mp(r, i));
	}
	sort(Q+1, Q+q+1, cmp);
	l = 0;
	r = 0;
	for (int i = 1; i <= q; i++) {
		int lf = Q[i].st;
		int rg = Q[i].nd.st;
		int t1 = query(1, 1, n, lf, rg);
		int t2 = query2(1, 1, n, lf, rg);
		while (l < lf) {
			hash[a[l++]]--;
		}
		while (l > lf) {
			hash[a[--l]]++;
		}
		while (r < rg) {
			hash[a[++r]]++;
		}
		while (r > rg) {
			hash[a[r--]]--;
		}
		if (t1 != t2) {
			ans[Q[i].nd.nd] = rg - lf + 1;
		} else {
			ans[Q[i].nd.nd] = (rg - lf + 1) - hash[t1];
		}
	}
	for (int i = 1; i <= q; i++) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

#define mid (lf + rg >> 1)
#define right (left | 1)
#define left (v << 1)

#define pb push_back
#define mp make_pair
#define nd second
#define st first

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

const ll linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e5 + 9;
const int kokn = sqrt(N);

int n, a[N], q, l, r, ans[N], tree[4*N], tree2[4*N], hash[N];

vector < pii > temp;

pair < int, pii > Q[N];

bool cmp(pair < int, pii > a, pair < int, pii > b) {
	if (a.st / kokn != b.st / kokn) {
		return a.st / kokn < b.st / kokn;
	}
	return a.nd.st < b.nd.st;
}

int build(int v, int lf, int rg) {
	if (lf == rg) {
		return tree[v] = a[lf];
	}
	return tree[v] = __gcd(build(left, lf, mid), build(right, mid+1, rg));
}

int build2(int v, int lf, int rg) {
	if (lf == rg) {
		return tree2[v] = a[lf];
	}
	return tree2[v] = min(build2(left, lf, mid), build2(right, mid+1, rg));
}

int query(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return -1;
	}
	if (l <= lf and rg <= r) {
		return tree[v];
	}
	int t1 = query(left, lf, mid, l, r);
	int t2 = query(right, mid+1, rg, l, r);
	if (t1 == -1) {
		return t2;
	} else if (t2 == -1) {
		return t1;
	}
	return __gcd(t1, t2);
}

int query2(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return inf;
	}
	if (l <= lf and rg <= r) {
		return tree2[v];
	}
	int t1 = query2(left, lf, mid, l, r);
	int t2 = query2(right, mid+1, rg, l, r);
	return min(t1, t2);
}

int main() {

	scanf("%lld", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		temp.pb(mp(a[i], i));
	}
	int t = 0;
	sort(temp.begin(), temp.end());
	for (int i = 0; i < temp.size(); i++) {
		if (i and (temp[i].st == temp[i-1].st)) {
			a[temp[i].nd] = t;
		} else {
			a[temp[i].nd] = ++t;
		}
	}
	scanf("%lld", &q);
	build(1, 1, n);
	build2(1, 1, n);
	for (int i = 1; i <= q; i++) {
		scanf("%lld %lld", &l, &r);
		Q[i] = mp(l, mp(r, i));
	}
	sort(Q+1, Q+q+1, cmp);
	l = 0;
	r = 0;
	for (int i = 1; i <= q; i++) {
		int lf = Q[i].st;
		int rg = Q[i].nd.st;
		int t1 = query(1, 1, n, lf, rg);
		int t2 = query2(1, 1, n, lf, rg);
		while (l < lf) {
			hash[a[l]]--;
			l++;
		}
		while (l > lf) {
			l--;
			hash[a[l]]++;
		}
		while (r < rg) {
			r++;
			hash[a[r]]++;
		}
		while (r > rg) {
			hash[a[r]]--;
			r--;
		}
		if (t1 != t2) {
			ans[Q[i].nd.nd] = rg - lf + 1;
		} else {
			ans[Q[i].nd.nd] = (rg - lf + 1) - hash[t1];
		}
	}
	for (int i = 1; i <= q; i++) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}