求助,拿题解对拍没问题,交上就re

UVA10140 Prime Distance

希望更丰富的展现?使用Markdown
by Dispwnl @ 2018-11-07 14:48:07


在程序前加``` d ```
by Kevin_Wa @ 2018-11-07 14:54:51


希望更丰富的展现?使用Markdown
by Tomone @ 2018-11-07 15:19:59


------------ 希望更丰富的展现?使用Markdown
by Ally_unstoppable @ 2018-11-07 16:32:13


@[Dispwnl](/space/show?uid=49206) 捕捉dalao
by BinDir0 @ 2018-12-11 19:12:51


``` #include<cstdio> #include<iostream> #include<cmath> #include<cstring> using namespace std; const int nn = 1000500,inf = 0x7ffffff; int l,r,tot,mi,ma,cnt; int pri[nn],now[nn]; bool c[nn],b[nn]; void shai(int x) { c[1] = 1; for ( int i=2; i<=x; i++ ) { if ( !c[i] ) pri[++tot] = i; for ( int j=1; pri[j]i <= x && j<=tot; j++ ) { c[ipri[j]] = 1; if ( i % pri[j] == 0 ) break; } } return; } int main() { int maxn = sqrt(inf); shai(maxn); // shai(100); // for ( int i=1; i<=tot; i++ ) cout<<pri[i]<<" "; cout<<endl; while(cin>>l>>r) { cnt = 0; memset(b,0,sizeof(b)); memset(now,0,sizeof(now)); for ( int i=1; i<=tot; i++ ) { if ( pri[i] > r ) break; for ( int j= max( (l + pri[i] - 1) / pri[i],2); jpri[i] <= r; j++ ) { b[jpri[i]-l] = 1; } } for ( int i=l; i<=r; i++ ) if ( !b[i-l] ) now[++cnt] = i; ma = mi = 1; for ( int i=2; i<cnt; i++ ) { if ( now[ma+1] - now[ma] < now[i+1] - now[i] ) ma = i; if ( now[mi+1] - now[mi] > now[i+1] - now[i] ) mi = i; } if ( cnt > 1 ) { cout<<now[mi]<<","<<now[mi+1]<<" are closest, "; cout<<now[ma]<<","<<now[ma+1]<<" are most distant."<<endl; } else cout<<"There are no adjacent primes."<<endl; // for ( int i=1; i<=cnt; i++ ) cout<<now[i]<<" "; // cout<<endl; } return 0; } ```
by hhoppitree @ 2019-11-06 16:44:32


|