#include<iostream> #include<cstring> #include<cmath> #include<cstdio> using namespace std; bool flag[50010]; int prime[8000]; bool r[1000010]; int num; void Init() { int i,j; num=0; memset(flag,true,sizeof(flag)); flag[1]=flag[0]=0; for(i=2;i<50000;i++) { if(flag[i]) prime[num++]=i; for(j=0;j<num && i*prime[j]<50000;j++) { flag[i*prime[j]]=false; if(i%prime[j]==0) break; } } } int main() { Init(); long long a,b,up,mina,minb,maxa,maxb,min,max,i,j,k; while(cin>>a>>b) { if(a==1) a++;//a=1的情况
min=20000000; max=0; memset(r,true,sizeof(r)); for(i=0;i<num && prime[i]*prime[i]<=b;i++) { k=a/prime[i]; if(k*prime[i]<a) k++; if(k<=1) k++; while(k*prime[i]<=b) { r[k*prime[i]-a]=false; k++; } } j=0;up=-1; for(i=0;i<=b-a;i++) { if(r[i]) { if(up==-1) up=i; else { if(min>i-up) { min=i-up; mina=up; minb=i; } if(max<i-up) { max=i-up; maxa=up; maxb=i; } up=i; } } } if(max==0) printf("There are no adjacent primes.\n"); else printf("%lld,%lld are closest, %lld,%lld are most distant.\n",mina+a,minb+a,maxa+a,maxb+a); } return 0; }