// yukicoder: No.732 3PrimeCounting // 2019.4.30 bal4u #include #define MAX 300005 #define SQRT 547 char notPrime[MAX] = { 1,1,0,0,1 }; // zero: if prime int ptbl[26000] = { 2 }; int sz; // 25997 void sieve(int n) { int i, j, b; for (i = 3; i <= SQRT; i += 2) if (!notPrime[i]) { for (j = i * i; j <= n; j += i) notPrime[j] = 1; } sz = 1; for (i = 3; i <= n; i += 2) { if (!notPrime[i]) ptbl[sz++] = i; } } int f[300005]; int main() { int N, i, j, a, b, c, d, t; long long ans; scanf("%d", &N); sieve(3*N); ans = 0; for (i = 3; (c = ptbl[i]) <= N; i++) { b = ptbl[i-1], t = ptbl[i-2] + b + c; a = i-2; while (a) f[ptbl[a--] + b]++; for (j = i+1; (d = ptbl[j]) <= t; j++) ans += f[d-c]; } printf("%lld\n", ans); return 0; }