//================================= // Created on: 2018/07/28 01:03:56 //================================= #include 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, -INF); for (int i = v.size() - 1; i >= 0; i--) { n[mask[v[i]]] = v[i]; } 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 large = ldp; for (int i = MAX - 1; i >= 0; i--) { for (int j = i; j > 0; j = (j - 1) & i) { large[i] = std::max(large[i], ldp[i - 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] + large[MAX - i - 1]); } std::cout << ans << std::endl; return 0; }