Pagini recente » Cod sursa (job #948735) | Cod sursa (job #2631982) | Cod sursa (job #2386028) | Cod sursa (job #32178) | Cod sursa (job #2507564)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<bool>isPrime(n + 1, true);
int cntPr = 0;
for(int i = 2; i <= n; ++i) {
if(isPrime[i]) {
for(int j = i + i; j <= n; j += i)
isPrime[j] = false;
cntPr++;
}
}
vector<int>P(cntPr);
for(int i = 2, j = 0; i <= n; ++i)
if(isPrime[i])
P[j++] = i;
vector<int>sol(n / 2 + 1);
function<void(int, int, int)>bkt = [&] (int pospr, int x, int luate) {
if(pospr == (int)P.size() || x == 0) {
if(x != 0) return;
return;
}
if(x != 0 && x - P[pospr] < 0)
return;
for(int ct = 0; x - ct * P[pospr] >= 0; ct++) {
if(ct != 0)
sol[luate + ct - 1] = P[pospr];
bkt(pospr + 1, x - ct * P[pospr], luate + ct);
}
};
bkt(0, n, 0);
cout << n;
}