#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

// Prints a complete factorization in the form:
//    if factors is empty: "1x<n>"
//    else: "<factors[0]>x<factors[1]>x...x<n>"
void printFactorization(const vector<int>& factors, int lastFactor) {
    if (factors.empty()) {
        cout << "1x" << lastFactor << "\n";
    } else {
        for (size_t i = 0; i < factors.size(); ++i) {
            cout << factors[i] << "x";
        }
        cout << lastFactor << "\n";
    }
}

// Recursive helper function.
//   n      : the remaining product to factorize.
//   start  : the minimum factor to try (to enforce non-decreasing order)
//   factors: the current factors chosen (by reference)
void printFactorizationsHelper(int n, int start, vector<int>& factors) {
    // Print the current factorization (factors followed by the remaining factor n).
    printFactorization(factors, n);
    
    // Try all factors i from 'start' up to √n.
    // If i divides n, then push i into factors and recurse with n/i.
    // (Because factors are chosen in non-decreasing order, each factorization is unique.)
    for (int i = start; i <= static_cast<int>(sqrt(n)); ++i) {
        if (n % i == 0) {
            factors.push_back(i);
            printFactorizationsHelper(n / i, i, factors);
            factors.pop_back();
        }
    }
}

int main() {
    int n = 24;
    vector<int> factors;
    // We start with factor 2 since 1 is handled specially in printFactorization.
    printFactorizationsHelper(n, 2, factors);
    return 0;
}
