C++简洁代码:

#include<bits/stdc++.h> 
using namespace std;

int main() {
    long n; cin >> n;
    for(int i = 2; i < n; i ++)
        while(n % i == 0) {
            cout << i << " ";
            n /= i;
        }
    cout << n << " ";
    return 0;
}