Pagini recente » Cod sursa (job #1616065) | Cod sursa (job #3181194) | Cod sursa (job #1027105) | Cod sursa (job #2447759) | Cod sursa (job #1499721)
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef INFOARENA
ifstream cin("nummst.in");
ofstream cout("nummst.out");
#endif
int n; cin >> n;
int g = 0;
for(int d = 2; d <= n; ++d)
if(n % d == 0) {
g = n / d;
break;
}
n /= g;
vector<int> primes;
auto isPrime = [] (int a) {
for(int i = 2; i * i <= a; ++i)
if(a % i == 0)
return false;
return true;
};
primes.push_back(1);
for(int i = 2; i <= n; ++i)
if(isPrime(i))
primes.push_back(i);
vector<double> best(n + 1, 0);
vector<int> from(n + 1, 0);
for(auto prime : primes) {
int current = prime;
vector<double> newBest = best;
vector<int> newFrom = from;
while(current <= n) {
vector<double> temp = best;
vector<int> tempFrom = from;
double logC = log(current);
for(int i = n - current; i >= 0; --i) {
if(current == n && i == 0)
continue;
if(temp[i] + logC > temp[i + current]) {
temp[i + current] = temp[i] + logC;
tempFrom[i + current] = i;
}
}
for(int i = 0; i <= n; ++i)
if(temp[i] > newBest[i]) {
newBest[i] = temp[i];
newFrom[i] = tempFrom[i];
};
current *= prime;
if(prime == 1)
break;
}
best = newBest;
from = newFrom;
}
for(int i = 1; i <= n; ++i)
if(best[i - 1] >= best[i]) {
best[i] = best[i - 1];
from[i] = i - 1;
}
vector<int> ans;
for(int now = n; now; now = from[now])
ans.push_back((now - from[now]) * g);
for(auto temp : ans)
cout << temp << " ";
cout << "\n";
}