Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么会WA啊 找了很多数据都没问题//#include <bits/stdc++.h> #include <iostream> #include <queue> #include <cmath> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; //typedef __int128 bll; const ll maxn = 1e6+100; const ll mod = 1e9+7; //const ld pi = acos(-1.0); const ll inf = 1e18; //const ld eps = 1e-5; //const ld e = exp(1); ll l,r,prime[maxn],lenp; bool flag[maxn]; bool flaglr[maxn]; void get_prime() { memset(flag,1,sizeof(flag)); flag[0] = flag[1] = 0; for(ll i = 2; i <= maxn; i++) { if(flag[i] == 1) { prime[++lenp] = i; for(ll j = 2; j*i <= maxn; j++) { flag[j*i] = 0; } } } } void get_prime2() { memset(flaglr,1,sizeof(flaglr)); for(ll i = 1; i <= lenp; i++) { ll tmp = l/prime[i]; for(ll j = tmp*prime[i]; j <= r; j += prime[i]) { if(j != prime[i] && j) { flaglr[ j-l+1 ] = 0; } } } return ; } void slove() { ll mi = inf,ma = -inf,pre = 0; ll mitmpa,mitmpb,matmpa,matmpb; for(ll i = 1; i <= (r-l+1); i++) { if(flaglr[i]) { if(pre) { if(i - pre > ma) { ma = i-pre; matmpa = pre+l; matmpb = i+l; } if(i - pre < mi) { mi = i-pre; mitmpa = pre+l; mitmpb = i+l; } } pre = i; } } if(mi != inf && ma != inf) { cout << mitmpa-1 << "," << mitmpb-1 << " are closest, "; cout << matmpa-1 << "," << matmpb-1 << " are most distant." << endl; } else { cout << "There are no adjacent primes." << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); get_prime(); while(cin >> l >> r) { if(l < 2) l = 2; get_prime2(); slove(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator