What is the most efficient algorithm to print all unique combinations of factors of a positive integer. For example if the given number is 24 then the output should be
#include
using namespace std;
int n;
// prod = current product of factors in combination vector
// curr = current factor
void fun(int curr, int prod, vector combination )
{
if(prod==n)
{
for(int j=0; jn) break;
if(n%i==0)
{
combination.push_back(i);
fun(i, i*prod, combination);
combination.resize(combination.size()-1);
}
}
}
int main()
{
cin>>n;
vector combination;
fun(2, 1, combination);
cout<<1<<" "<