#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> solve(int l, int r, vector &f) { if(r - l == 1) { return {{0}, {0}}; } int m = (l + r) / 2; auto [l2, l3] = solve(l, m, f); auto [r2, r3] = solve(m, r, f); vector a2(2 * (r - l) - 1), a3(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 n2 = convolution_ll(fl, fr); rep(i, n2.size()) { a2[m - l + i] += n2[i]; } rep(i, l2.size()) { a2[i] += l2[i]; } rep(i, r2.size()) { a2[2 * (m - l) + i] += r2[i]; } } { auto n2_1 = convolution_ll(l2, fr); auto n1_2 = convolution_ll(fl, r2); rep(i, n2_1.size()) { a3[m - l + i] += n2_1[i]; } rep(i, n1_2.size()) { a3[2 * (m - l) + i] += n1_2[i]; } rep(i, l3.size()) { a3[i] += l3[i]; } rep(i, r3.size()) { a3[3 * (m - l) + i] += r3[i]; } } return {a2, a3}; } 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<1>(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; }