#pragma GCC optimize ("O3") #include "bits/stdc++.h" using namespace std; using ll = long long int; #define debugos cout #define debug(v) {printf("L%d %s > ",__LINE__,#v);debugos<<(v)< ",__LINE__,#v);for(auto e:(v)){debugos< ",__LINE__,#m);for(int x=0;x<(w);x++){debugos<<(m)[x]<<" ";}debugos<\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){debugos<<(m)[y][x]<<" ";}debugos<::type>::type cnt=0;(cnt)<(l);++(cnt)) #define rrepeat(cnt,l) for(auto cnt=(l)-1;0<=(cnt);--(cnt)) #define iterate(cnt,b,e) for(auto cnt=(b);(cnt)!=(e);++(cnt)) #define diterate(cnt,b,e) for(auto cnt=(b);(cnt)!=(e);--(cnt)) const ll MD = 1000000007ll; const long double PI = 3.1415926535897932384626433832795L; inline void assert_call(bool assertion, function f) { if (!assertion) { cerr << "assertion fault:" << endl; f(); abort(); } } template inline ostream& operator <<(ostream &o, const pair p) { o << '(' << p.first << ':' << p.second << ')'; return o; } template inline ostream& _ostream_vecprint(ostream& os, const Vec& a) { os << '['; for (const auto& e : a) os << ' ' << e << ' '; os << ']'; return os; } template inline ostream& operator<<(ostream& o, const vector& v) { return _ostream_vecprint(o, v); } template inline ostream& operator<<(ostream& o, const array& v) { return _ostream_vecprint(o, v); } template inline T& maxset(T& to, const T& val) { return to = max(to, val); } template inline T& minset(T& to, const T& val) { return to = min(to, val); } void bye(string s, int code = 0) { cout << s << endl; exit(code); } mt19937_64 randdev(8901016); template inline T rand(T l, T h) { return uniform_int_distribution(l, h)(randdev); } template<> inline double rand(double l, double h) { return uniform_real_distribution(l, h)(randdev); } template<> inline float rand(float l, float h) { return uniform_real_distribution(l, h)(randdev); } template class IsPrimeC { bool d_[Max + 1]; template static T cesqrt(T s) { double x = s / 2.0; double prev = 0.0; while (x != prev) { prev = x; x = (x + s / x) / 2.0; } return x; } public: IsPrimeC() : d_() { d_[0] = d_[1] = 1; int sqh = cesqrt(Max); for (int i = 2; i <= sqh; i++) { if (d_[i] == 0) { for (int j = i * i; j <= Max; j += i) { // i*i d_[j] = 1; } } } for (int i = 0; i <= Max; ++i) d_[i] = !d_[i]; } inline bool operator[](int x) const { return d_[x]; } }; template class PrimeList { int d_[Max]; public: PrimeList() : d_() { int n = 1; d_[0] = 2; for (int x = 3; n < Max; ++x) { bool f = true; for (int i = 0; d_[i] * d_[i] <= x; ++i) if (x % d_[i] == 0) { f = false; break; } if (f) d_[n++] = x; } } inline int operator[](int x) const { return d_[x]; } template class iterator { const PrimeList& pl; int ptr = 0; public: iterator(const decltype(pl)& _pl, int _ptr = 0) :pl(_pl), ptr(_ptr) { } int operator*() const { return pl[ptr]; } iterator& operator++() { ptr++; return *this; } // prefix inline bool operator!=(const iterator& it) const { return ptr != it.ptr ? !(Max < ptr && Max < it.ptr) : false; } inline bool operator==(const iterator& it) const { return ptr != it.ptr ? (Max < ptr && Max < it.ptr) : true; } }; PrimeList::iterator begin() const { return PrimeList::iterator(*this, 0); } PrimeList::iterator end() const { return PrimeList::iterator(*this, Max); } }; IsPrimeC<300001> isPrime; PrimeList<300001> primeList; ll N; int main() { cin >> N; vector dp; dp.resize(300001); int last = 0; for (last = 0; primeList[last] <= N; ++last) { dp[primeList[last]] = 1; } repeat(_, 2) { vector dp2(300001); rrepeat(i, last) { int p = primeList[i]; for (int j = 2; j + p <= 300001; ++j) { dp2[j + p] += dp[j]; } } dp.swap(dp2); } ll ans = 0; for (ll p : primeList) { if (p >= dp.size()) break; ans += dp[p]; } for (int i = 0; primeList[i] <= N; ++i) { int vi = primeList[i]; for (int j = i + 1; primeList[j] <= N; ++j) { if (vi * 2 + primeList[j] >= dp.size()) break; ans -= isPrime[vi * 2 + primeList[j]] * 3; ans -= isPrime[vi + primeList[j] * 2] * 3; } } cout << ans / 6 << endl; return 0; }