1 solutions

  • -1
    @ 2022-2-10 15:35:58

    把刚刚打的新鲜的欧拉筛稍加改造就可以了

    #include<iostream>
    using namespace std;
    const int N=1e5+7;
    
    int g,prime[N];
    bool v[N];
    
    
    void shine(){
    	v[0]=true;
    	v[1]=true;
    	for(int i=2;i<N;++i){
    		if(!v[i])
    			prime[++g]=i;
    		for(int j=1;j<=g&&i*prime[j]<=N;++j){
    			v[i*prime[j]]=true;
    			if(i%prime[j]==0)
    				break;
    		}
    	}
    }
    
    int main(){
    	int n;
    	shine();
    	while(scanf("%d",&n)!=EOF){
    		int a,b;
    		a=n/2;
    		b=n/2;
    		for(int i=0;i<n/2;i++){
    			a--;
    			b++;
    			if(!v[a]&&!v[b]){
    				cout<<a<<" "<<b<<endl;
    				break;
    			}
    		}
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    328
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    # Submissions
    128
    Accepted
    42
    Uploaded By