//================================= // Created on: 2018/07/28 01:03:56 //================================= #include #define show(x) std::cerr << #x << " = " << (x) << std::endl template std::ostream& operator<<(std::ostream& os, const std::vector& v) { os << "["; for (const auto& p : v) { os << p << ","; } return (os << "]\n"); } int main() { constexpr int NUM = 11; constexpr int MAX = 1 << NUM; int N; std::cin >> N; std::vector mask(N + 1, 0), maxp(N + 1, 0); for (int i = 2, cnt = 0; i <= N; i++) { if (maxp[i] != 0) { continue; } for (int j = 1; i * j <= N; j++) { mask[i * j] |= (cnt < NUM ? (1 << cnt) : 0), maxp[i * j] = i; } cnt++; } std::map> mp; for (int i = 2; i <= N; i++) { if (maxp[i] > 31) { mp[maxp[i]].push_back(i); } } constexpr int INF = 1 << 30; std::vector ldp(MAX, 0); for (const auto& p : mp) { const auto& v = p.second; std::vector n(MAX, 0); for (const int e : v) { n[mask[e]] = e; } for (int i = MAX - 1; i >= 0; i--) { ldp[i] += n[0]; for (int j = i; j > 0; j = ((j - 1) & i)) { ldp[i] = std::max(ldp[i], ldp[i - j] + n[j]); } } } std::vector dp(MAX, -INF); dp[0] = 0; for (int i = 2; i <= N; i++) { if (maxp[i] > 31) { continue; } for (int j = MAX - 1; j >= 0; j--) { if (dp[j] == -INF or (j & mask[i]) > 0) { continue; } dp[j | mask[i]] = std::max(dp[j | mask[i]], dp[j] + i); } } int ans = 0; for (int i = 0; i < MAX; i++) { ans = std::max(ans, dp[i] + ldp[MAX - i - 1]); } std::cout << ans << std::endl; return 0; }