Pagini recente » Cod sursa (job #2980556) | Cod sursa (job #238206) | Cod sursa (job #1918297) | Cod sursa (job #56565) | Cod sursa (job #2345252)
#include <bits/stdc++.h>
#define llg long long
#define MAXDIV 7505
#define MAXN 4205
llg N, K, NDiv, Div[MAXDIV];
int DP[MAXN][MAXN];
std::unordered_map <llg, int> Map;
std::ifstream In ("desc.in");
std::ofstream Out("desc.out");
void Citire() {
In >> N >> K;
}
void Rezolvare() {
for (llg div=1; div*div <= N; ++div)
if (N%div == 0) {
if (div != 1)
Div[++NDiv] = div;
if (div != N/div)
Div[++NDiv] = N/div;
} std::sort(Div+1, Div+NDiv+1);
Div[0] = 1;
for (int i=1; i<=N; ++i)
Map[Div[i]] = i;
DP[0][NDiv] = 1;
for (int i=0, j; i<=NDiv; ++i) {
for (j=NDiv; j>0; --j)
DP[i][j] += DP[i][j+1];
for (j=i+1; j<=NDiv; ++j) {
if (Div[j] % Div[i] != 0)
continue;
llg frac = Div[j]/Div[i];
if (Map.find(frac) == Map.end())
continue;
DP[j][Map[frac]] += DP[i][Map[frac]];
}
} Out << DP[NDiv][1] << '\n';
int l = NDiv, r = 1;
while (K) {
if (DP[l][r] - DP[l][r+1] < K) {
K -= (DP[l][r] - DP[l][r+1]);
++r;
}
else {
if (l == r && K == 1) {
Out << Div[r] << '\n';
K = 0;
}
else {
Out << Div[r] << '\n';
N /= Div[r];
l = Map[N];
}
}
}
}
int main()
{
Citire();
Rezolvare();
return 0;
}