# Cod sursa(job #2559237)

Utilizator Data 27 februarie 2020 10:02:47 Descompuneri 40 cpp-64 done Arhiva de probleme 1.28 kb
``````#include <fstream>
#include <vector>
#include <algorithm>
#include <unordered_map>

#define N 4095

using namespace std;

ifstream f ( "desc.in" );
ofstream g ( "desc.out" );

unordered_map < long long, int > h;
int d[N][N];
long long n, k, v[N], dv;

int main()
{   int l = 0, i, j;
f >> n >> k;
for ( dv = 1; dv * dv < n; dv++ ){
if ( n % dv == 0 ){
v[++l] = dv;
v[++l] = n / dv;
}
}
if ( dv * dv == n )
v[++l] = dv;
sort ( v + 1, v + l + 1 );
for ( i = 1; i <= l; i++ )
h[v[i]] = i;
d[1][1] = 1;
for ( i = 2; i <= l; i++ ){
d[i][i] = 1;
for ( j = i - 1; j >= 2; j-- ){
d[i][j] = d[i][j + 1];
if ( v[i] % v[j] == 0 ){
dv = v[i] / v[j];
int poz = h[dv];
d[i][j] += d[poz][j];
}
}
d[i][1] = d[i][2];
}
g << d[l][1] << '\n';
k = l - k + 1;
int line = l;
long long num = n;
while ( num > 1 ){
for ( i = line; i >= 1; i-- ){
if ( d[line][i] >= k )
break;
}
g << v[i] << ' ';
k -= d[line][i + 1];
num = num / v[i];
line = h[num];
}
return 0;
}
``````