C++ solution without using sorting algorithm.Time complexity O(sqrt(n))


#1

vector Solution::allFactors(int A) {
vectorans;
int i;
for( i=1;ii<=(A);i++){
if(A%i==0){
ans.push_back(i);
}
}
for(int j=sqrt(A);j>=1;j–){
if(j
j!=A &&A%j==0){
ans.push_back(A/j);
}
}
return ans;

}