/* -*- coding: utf-8 -*- * * 732.cc: No.732 3PrimeCounting - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_P = MAX_N * 3; /* typedef */ typedef long long ll; typedef vector vi; /* global variables */ bool primes[MAX_P + 1]; int ds[MAX_P]; /* subroutines */ int gen_primes(int maxp, vi &pnums) { memset(primes, true, sizeof(primes)); primes[0] = primes[1] = false; int p; for (p = 2; p * p <= maxp; p++) if (primes[p]) { pnums.push_back(p); for (int q = p * p; q <= maxp; q += p) primes[q] = false; } for (; p <= maxp; p++) if (primes[p]) pnums.push_back(p); return (int)pnums.size(); } /* main */ int main() { int n; scanf("%d", &n); int n3 = n * 3; vi pnums; int pn = gen_primes(n3, pnums); //printf("pn=%d\n", pn); memset(ds, 0, sizeof(ds)); ll sum = 0; for (int i = 2; pnums[i] <= n; i++) { for (int j = 0; j < i - 1; j++) ds[pnums[j] + pnums[i - 1]]++; for (int j = i + 1; j < pn; j++) sum += ds[pnums[j] - pnums[i]]; } printf("%lld\n", sum); return 0; }