/* * @Author: kabbo * @Date: 2020-06-24 08:40:07 * @Last Modified by: kabbo * @Last Modified time: 2020-06-24 08:49:58 */ #include using namespace std; #define pii pair #define endl '\n' #define ull unsigned long long #define ll int64_t #define ar array // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html template class y_combinator_result { Fun fun_; public: template explicit y_combinator_result(T &&fun) : fun_(std::forward(fun)) {} template decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward(args)...); } }; template decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result>(std::forward(fun)); } //const int mod = 1e9 + 7; using u64 = uint64_t; using u128 = __uint128_t; #define sc1(x) scanf("%lld", &(x)); mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); void dbg_out() { cerr << endl; } template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifndef NEAL_DEBUG #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif /*Well, probably you won't understand anything, because you didn't try to understand anything in your life, you expect all hard work to be done for you by someone else. Let's start*/ const int X = 20000; bitset is_prime; vector pf; vector pr; void init() { pf.resize(X, 0); is_prime.flip(); is_prime[0] = is_prime[1] = false; for (int i = 2; i < X; i++) { if (is_prime[i]) { pr.push_back(i); pf[i] = i; } for (int p : pr) { if (ll(i) * p >= X) break; pf[i * p] = p; is_prime[i * p] = false; if (i % p == 0) break; } } } void solve() { int n; cin >> n; int sz = pr.size(); // dbg(sz); vector memo(sz + 5, vector(X + 1, (int)-1)); auto dp = y_combinator( [&](auto self, int st, int n) -> int { if (n < 0) return -(int)1e5; if (st == sz) { if (n == 0) return 0; else return -(int)1e5; } int &res = memo[st][n]; if (res != -1) return res; int a1 = 1 + self(st + 1, n - pr[st]); int a2 = self(st + 1, n); return res = max(a1, a2); } ); int ans = dp(0, n); cout << (ans < 1 ? -1 : ans) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); init(); solve(); return 0; }