#include using namespace std; #define REP(i,n) for (int i=0;i<(n);i++) #define REP2(i,m,n) for (int i=m;i<(n);i++) typedef long long ll; typedef long double ld; const int MAX = 300300; int N; bool is_P[MAX]; vector P; vector P1; vector P2; map A; map B; int main() { cin.tie(0); ios::sync_with_stdio(false); ll ans = 0; cin >> N; REP(i, 3*N+1) is_P[i] = true; is_P[0] = is_P[1] = false; for (int i = 2; i <= 3*N; ++i) { if (!is_P[i]) continue; if (i <= N) P.push_back(i); for (int j = i + i; j <=3*N; j += i) is_P[j] = false; } int M = P.size(); REP2(i, 2, M) { if (P[i] % 3 == 1) P1.push_back(P[i]); if (P[i] % 3 == 2) P2.push_back(P[i]); } REP(i, P1.size()) REP2(j, i+1, P1.size()) A[P1[i]+P1[j]] += 1; REP(i, P2.size()) REP2(j, i+1, P2.size()) B[P2[i]+P2[j]] += 1; for (auto itr = A.begin(); itr != A.end(); ++itr) if (is_P[itr->first - 3]) ans += itr->second; for (auto itr = B.begin(); itr != B.end(); ++itr) if (is_P[itr->first - 3]) ans += itr->second; REP(i, P1.size()) for (auto itr = B.begin(); itr != B.end(); ++itr) if (is_P[P1[i] + itr->first]) ans += itr->second; REP(i, P2.size()) for (auto itr = A.begin(); itr != A.end(); ++itr) if (is_P[P2[i] + itr->first]) ans += itr->second; cout << ans << endl; }