素数区间
include
include<stdio.h>
include<stdlib.h>
include
include
include<float.h>
include<string.h>
include
include
include
define sf scanf
define pf printf
define scf(x) scanf("%d",&x)
define scff(x,y) scanf("%d%d",&x,&y)
define prf(x) printf("%d ",x)
define mm(x,b) memset((x),(b),sizeof(x))
define rep(i,a,n) for (int i=a;i<n;i++)
define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e5+7;
bool sushu[N];
void init()
{
mm(sushu,false);
sushu[0]=sushu[1]=true;
rep(i,2,N)
{
if(!sushu[i])
{
if(i>N/i) continue;
for(int j=i*i;j<N;j+=i)
sushu[j]=true;
}
}
}
int main()
{
init();
int re,n;
scf(re);
while(re)
{
scf(n);
if(n0||n1)
{
pf("0
");continue;
}
if(!sushu[n])
pf("0
");
else
{
int l,r;
l=n;r=n;
while(sushu[l-1])
l--;
while(sushu[r+1])
r++;
prf(r-l+1);
}
}
return 0;
}
区间
include
include<stdio.h>
include<stdlib.h>
include
include
include<float.h>
include<string.h>
include
include
include
define sf scanf
define pf printf
define scf(x) scanf("%d",&x)
define scff(x,y) scanf("%d%d",&x,&y)
define prf(x) printf("%d ",x)
define mm(x,b) memset((x),(b),sizeof(x))
define rep(i,a,n) for (int i=a;i<n;i++)
define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e5+12;
struct qujian
{
int l,r;
}x[N];
int main()
{
int n;scf(n);
int maxn=0,minn=inf;
rep(i,1,n+1)
{
scff(x[i].l,x[i].r);
minn=min(minn,x[i].l);
maxn=max(maxn,x[i].r);
}
rep(i,1,n+1)
{
if(x[i].lminn&&x[i].rmaxn)
{
prf(i);
return 0;
}
}
pf("-1
");
return 0;
}