#include <bits/stdc++.h>
using namespace std;
const int N=100010;
int a[N],n,m;
int check(int n)
{
if (n==0 || n==1) return 0;
for (int i=2;i*i<=n;i++)
{
if (n%i==0)
{
return 0;
}
}
return 1;
}
int main() {
freopen("Jelly.in","r",stdin);
freopen("Jelly.out","w",stdout);
cin>>n>>m;
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
while (m--)
{
int l,r,ret=0;
scanf("%d%d",&l,&r);
for (int i=l;i<=r;i++)
{
for (int j=i;j<=r;j++)
{
int cnt=a[i];
for (int k=i+1;k<=j;k++)
{
cnt=cnt|a[k];
}
if (check(cnt))
{
ret++;
}
}
}
printf("%d\n",ret);
}
}