题目代码
#include#include #include #include using namespace std;typedef long long LL;const int maxn=5e4+7;const int maxm=1000007;int prime[maxn];bool check[maxm];int cnt=0;void Prime(){ for(int i=2;i 1){ check[j*prime[i]-l]=true; } } for(LL i=0;i<=r-l;i++){ if(!check[i]&&!flag){ flag++; minl=maxl=i; } else if(!check[i]){ flag++; if(flag==2){ minr=maxr=i; } else{ if(i-pre maxr-maxl)maxr=i,maxl=pre; } pre=i; } } if(flag<2)printf("There are no adjacent primes.\n"); else printf("%lld,%lld are closest, %lld,%lld are most distant.\n",minl+l,minr+l,maxl+l,maxr+l); } return 0;}