Pagini recente » Cod sursa (job #3206371) | Cod sursa (job #269368) | Cod sursa (job #3234086) | Cod sursa (job #644668) | Cod sursa (job #2261051)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("nummst.in"); ofstream fout ("nummst.out");
const int nmax = 1e4;
int r[nmax + 1];
int st[nmax + 1];
double dp[nmax + 1];
double e;
double lg[nmax + 1];
vector<pair<int, int>> aux, dsc;
vector<pair<int, int>> f[nmax + 1], prec[nmax + 1];
void descomp (int x) {
dsc.clear();
for (int i = 2; i * i <= x; ++ i) {
if (x % i == 0) {
int p = 0;
while (x % i == 0) {
++ p;
x /= i;
}
dsc.push_back({i, p});
}
}
if (x > 1) {
dsc.push_back({x, 1});
}
}
void solve (vector<pair<int, int>> &v) {
aux.clear();
int i = 0, j = 0;
while (i < (int)dsc.size() && j < (int)v.size()) {
if (dsc[i].first == v[j].first) {
aux.push_back({dsc[i].first, dsc[i].second + v[j].second});
++ i; ++ j;
} else if (dsc[i].first < v[j].first) {
aux.push_back(dsc[i ++]);
} else {
aux.push_back(v[j ++]);
}
}
for (; i < (int)dsc.size(); ++ i) aux.push_back(dsc[i]);
for (; j < (int)v.size(); ++ j) aux.push_back(v[j]);
e = 0;
for (auto k : aux)
e += lg[k.first] * k.second;
}
int main () {
int n, g;
fin >> n;
for (int i = 2; i * i <= n; ++ i) {
if (n % i == 0) {
g = n / i;
n = i;
break;
}
}
for (int i = 1; i <= n; ++ i)
lg[i] = log(i);
for (int i = 0; i <= n; ++ i)
dp[i] = -1, r[i] = i;
for (int i = 1; i <= n; ++ i) {
descomp(i);
prec[i] = dsc;
for (int j = 1; j <= i && j + i <= n; ++ j) {
solve(prec[j]);
if (e > dp[i + j]) {
st[i + j] = j;
dp[i + j] = e;
r[i + j] = i;
f[i + j] = aux;
}
}
}
for (int i = 1; i <= n; ++ i) {
dsc = prec[i];
for (int j = 1; i + j <= n; ++ j) {
solve(f[j]);
if (e > dp[i + j]) {
dp[i + j] = e;
st[i + j] = st[j];
r[i + j] = i;
f[i + j] = aux;
}
}
}
vector<int> sol;
int x = st[n];
while (n != x) {
sol.push_back(r[n]);
n -= r[n];
}
sol.push_back(x);
for (auto i : sol)
fout << i * g << " ";
fout << "\n";
fin.close();
fout.close();
return 0;
}