How can i optimize it more


#1

vector Solution::primesum(int A) {
vectorn;
for(int i=0;i<2;i++){
n.push_back(0);}
for(int i=2;i<=A;i++){
n.push_back(1);}
vectorans;
for(int i=0;i<=sqrt(A);i++){
if(n[i]==1){
for(int j=2;j*i<=A;j++){
n[i*j]=0;}}}
for(int i=0;i<=A;i++){
if(n[i]==1){
ans.push_back(i);}}
sort(ans.begin(),ans.end());
vectorprime;
for(int i=0;i<ans.size();i++){
for(int j=i;j<ans.size();j++){
if(ans[i]+ans[j]==A){
prime.push_back(ans[i]);
prime.push_back(ans[j]);
break;}}}
sort(prime.begin(),prime.begin());
vectorfinal(1,prime[0]);
//final.push_back(prime[0]);
for(int i=0;i<prime.size();i++){
if(prime[0]+prime[i]==A){
final.push_back(prime[i]);
break;
}
}
return final;}