Doubt on NTRIPLETS

In yesterday’s contest, while solving the NTRIPLETS problem, I was able to make the problem work but I didn’t understand why it didn’t run in my previous code, since the code was almost exactly the same. I just used vector(in the wrong code) instead of set (in the correct code). There were no duplicate values, and no need to sort was required. So why is it so?

Correct Code snippet:
{ set res;
res.insert(1);
for(int i = 2; i * i < n; i++){
if(n % i == 0){
res.insert(i);
res.insert(n/i);
break;
}
}
}
if(res.size() < 3)
cout<<-1;
else{
for(auto it:res)
cout<<it<<" “;
}
cout<<”\n";
}

Wrong code snippet:
{vector res;
res.push_back(1);
for(int i = 2; i * i < n; i++){
if(n % i == 0){
res.push_back(i);
res.push_back(n/i);
break;
}
}
}
if(res.size() < 3)
cout<<-1;
else{
for(auto it:res)
cout<<it<<" “;
}
cout<<”\n";
}

As it can be seen, only change in the container.

Error for the wrong code is as follows:

So, can someone please help me?

second one is also giving AC
check this code->
https://www.codechef.com/viewsolution/84582910