How do I optimize it more?


#1

bool isPrime(int x){
for(int i=2;i*i<=x;i++){
if(x%i==0){
return false;
}
}
return true;
}
vector Solution::primesum(int A) {

vector <int> v;

for(int i=2;i<=A/2;i++){
    if (isPrime(i)==true){
        if (isPrime(A-i)==true){
            //cout<<i<<"+"<<A-i<<"="<<A<<endl;
            v.push_back(i);
            v.push_back(A-i);
            return v;
            
        }
    }
    
}

}


#2

The solutions are gonna be a pair of odd numbers so you can change your loop to increment by 2