#include #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) #define ALL(x) begin(x), end(x) using namespace std; template inline void chmax(T & a, T const & b) { a = max(a, b); } constexpr int MAX_N = 1262; constexpr int PRIMES_SIZE = 11; const int primes[PRIMES_SIZE] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 }; int solve(int n) { assert (n <= MAX_N); vector mask(n + 1); // of small prime factors REP3 (i, 2, n + 1) { REP (j, PRIMES_SIZE) { if (i % primes[j] == 0) { mask[i] |= 1 << j; } } } vector > dp(n + 1); REP3 (i, 2, n + 1) { dp[i] = dp[i - 1]; REP (used, 1 << PRIMES_SIZE) { if ((used & mask[i]) == 0) { chmax(dp[i][used | mask[i]], dp[i - 1][used] + i); } } } return *max_element(ALL(dp[n])); } int main() { int n; cin >> n; cout << solve(n) << endl; return 0; }