How do i optimize it?


#1

bool checkprime(int num)
{
int count=0;
for(int i=1;i<=num/2;i++)
{
if(num%i==0)
{
count++;
}
}
if(count==2 || count<2)
return 1;
else
return 0;
}
vector Solution::primesum(int A) {
int temp=A;
vectorres;
while(A>=2)
{
if(checkprime(A))
res.push_back(A);

    A--;
}
sort(res.begin(),res.end());
vector<int>ans; 
int index=0;
int size=res.size()-1;
while(index<=size)
{
    if((res[index]+res[size])==temp)
    {
        ans.push_back(res[index]);
        ans.push_back(res[size]);
        break;
    }else if((res[index]+res[size])>temp)
    size--;
    else
    index++;
}
return ans;

}