#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; vector sieve(int n) { vector f(n + 1); for (int i = 3; i <= n; i += 2) f[i] = 1; for (int i = 3; i <= sqrt(n); i += 2) if (f[i]) for (int j = i * 3; j <= n; j += i) f[j] = 0; vector res; if (n >= 2)res.push_back(2); for (int i = 3; i <= n; i += 2) if (f[i]) res.push_back(i); return res; } int N, cnt[200001]; vi P, Q; vi G[100001]; void solve() { cin >> N; P = sieve(N); Q = sieve(3 * N); each(b, P) { for (auto it = lower_bound(all(P), b + 1); it != P.end(); ++it) { int c = *it; cnt[b + c]++; G[b].push_back(b + c); } G[b].shrink_to_fit(); } ll ans = 0; each(a, P) { each(sm, G[a])cnt[sm]--; for (auto it = lower_bound(all(Q), a * 3); it != Q.end(); ++it) { auto p = *it; if (p-a < 200001) { ans += cnt[p - a]; } } } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }