bdfz_2024_summer/day8/T493931/T493931.cpp

72 lines
1.7 KiB
C++

#include<bits/stdc++.h>
using namespace std;
const int MAX_T=1e3+5,MAX_N=1e6+5;
int a[MAX_T];
int n,maxn=INT_MIN;
bool is_unprime[MAX_N];
int readint();
void fill_unprime(bool isprime[],int num,int end);
int main(int argc,char *argv[]){
#ifdef OITEST
#define AS(c){if(!(c)){cerr<<"assert failed! :"<<#c<<endl;return 1;}}
AS(argc==3)
cout<<"TESTING:"<<endl<<argv[0]<<"\n"<<argv[1]<<"\n"<<argv[2]<<endl;
auto fin = freopen(argv[1],"r",stdin);
AS(fin!=NULL)
ifstream afile(argv[2]);
AS(afile.is_open()==true)
stringstream ss;
#define cout ss
#endif
ios::sync_with_stdio(false);
n=readint();
for(int i=1;i<=n;i++){
a[i]=readint();
maxn=max(a[i],maxn);
}
for(int i=2;i<=(maxn/2)+1;i++){
if(is_unprime[i]==false){
fill_unprime(is_unprime,i,maxn);
}
}
for(int i=1;i<=n;i++){
for(int j=(a[i]/2);j<=a[i];j++){
if(!is_unprime[j]&&!is_unprime[a[i]-j]){
cout<<a[i]-j<<" "<<j<<"\n";
#ifdef OITEST
int cans1,cans2,myans1,myans2;
ss>>myans1>>myans2;
afile>>cans1>>cans2;
AS(cans1==myans1)
AS(cans2==myans2)
#endif
break;
}
}
}
cout<<endl;
}
void fill_unprime(bool isprime[],int num,int end){
for(int i=num*2;i<=end;i+=num){
isprime[i]=true;
}
}
int readint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}