// yukicoder: No.732 3PrimeCounting // 2019.4.30 bal4u #include #define MAX 300000 #define SQRT 547 char notPrime[MAX+2] = { 1,1,0,0,1 }; // zero: if prime int ptbl[26000] = { 2 }; int sz; // 25997 void sieve() { int i, j, b; for (i = 3; i <= SQRT; i += 2) if (!notPrime[i]) { for (j = i * i; j <= MAX; j += i) notPrime[j] = 1; } sz = 1; for (i = 3; i <= MAX; 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; sieve(); scanf("%d", &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; }