#include #include using ll = long long; #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) #define REP(i, m, n) for(ll i = (ll)(m); i < (ll)(n); i++) using namespace std; using namespace atcoder; using mint = modint998244353; tuple, vector, vector> solve(int l, int r, vector &f) { if(r - l == 1) { return {{0}, {0}, {0}}; } int m = (l + r) / 2; auto [l12, l23, l123] = solve(l, m, f); auto [r12, r23, r123] = solve(m, r, f); vector a12(2 * (r - l) - 1), a23(2 * (r - l) - 1), a123(3 * (r - l) - 2); vector fl(m - l), fr(r - m); rep(i, m - l) { fl[i] = f[l + i]; } rep(i, r - m) { fr[i] = f[m + i]; } { auto n12 = convolution_ll(fl, fr); rep(i, n12.size()) { a12[m - l + i] += n12[i]; } rep(i, l12.size()) { a12[i] += l12[i]; } rep(i, r12.size()) { a12[2 * (m - l) + i] += r12[i]; } } { auto n23 = convolution_ll(fl, fr); rep(i, n23.size()) { a23[m - l + i] += n23[i]; } rep(i, l23.size()) { a23[i] += l23[i]; } rep(i, r23.size()) { a23[2 * (m - l) + i] += r23[i]; } } { auto n12_3 = convolution_ll(l12, fr); auto n1_23 = convolution_ll(fl, r23); rep(i, n12_3.size()) { a123[m - l + i] += n12_3[i]; } rep(i, n1_23.size()) { a123[2 * (m - l) + i] += n1_23[i]; } rep(i, l123.size()) { a123[i] += l123[i]; } rep(i, r123.size()) { a123[3 * (m - l) + i] += r123[i]; } } return {a12, a23, a123}; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector is_prime(3 * n + 1, 1); is_prime[0] = is_prime[1] = 0; for(int i = 2; i <= 3 * n; i++) { if(!is_prime[i]) { continue; } for(int j = 2 * i; j <= 3 * n; j += i) { is_prime[j] = 0; } } vector f(n + 1); rep(i, n + 1) f[i] = is_prime[i]; auto ret = get<2>(solve(0, n + 1, f)); ll ans = 0; rep(i, 3 * n + 1) { ans += is_prime[i] ? ret[i] : 0; } cout << ans << endl; return 0; }