#include #include #include using namespace std; int n; bool is_prime[300001]; int primes[100000]; int cnt[300001]; int max_exist = -1; void setPrime() { for (int i = 2; i <= 3 * n; i++) is_prime[i] = true; for (int i = 2; i <= 3 * n; i++) { if (is_prime[i]) { for (int j = i * 2; j <= 3 * n; j += i) { is_prime[j] = false; } } } int id = 0; for (int i = 2; i <= 400000; i++) { if (is_prime[i]) primes[id++] = i; } } int main() { cin >> n; setPrime(); long long ans = 0; cnt[primes[0] + primes[1]]++; max_exist = max(max_exist, primes[0] + primes[1]); for (int i = 2; primes[i] <= n; i++) { for (int j = i + 1; primes[j] - primes[i] <= max_exist; j++) { ans += cnt[primes[j] - primes[i]]; } for (int j = 0; j < i; j++) { cnt[primes[j] + primes[i]]++; } max_exist = max(max_exist, primes[i] + primes[i-1]); } cout << ans << endl; return 0; }