#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned int ui; const ll MOD = (1e+9)+7; const ll INF = (ll)1000000007 * 1000000007; typedef pair P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; typedef complex Point; const ld eps = 1e-11; const ld pi = acos(-1.0); typedef pair LP; typedef pair LDP; int isp[1300]; vector used; int h; int gcd(int x,int y) { if (x < y)swap(x, y); while (y) { int r = x % y; x = y; y = r; } return x; } int ma = 0; void sum(int k,int s) { if (k == 1)return; if (k >= h && isp[k]) { sum(k - 1,s); return; } int len = used.size(); bool f = true; rep(i, len) { if (gcd(used[i], k) > 1) { f = false; } } if (!f) { sum(k - 1,s); return; } else { sum(k - 1, s); used.push_back(k); sum(k - 1, s + k); ma = max(ma, s + k); used.pop_back(); return; } } int main() { fill(isp, isp + 1300, 1); Rep(i, 2, 1300) { if (isp[i]) { for (int j = i * 2; j < 1300; j += i) { isp[j] = 0; } } } int n; cin >> n; h = n/2 + 1; int out = 0; for (int i = n; i >= h; i--) { if (isp[i])out += i; } sum(n, 0); cout << out + ma << endl; return 0; }