#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair p_ii; #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i ) #define rep(i,n) REP(i,0,n) const int INF = 1e9; const double PI = acos(-1.0); const ll MOD = 1e9 + 7; bool is_prime[300100]; int prime[300100]; int cnt[300100]; int ex_max = -1; void sieve(int n) { int p = 0; rep(i, n + 1)is_prime[i] = true; is_prime[0] = is_prime[1] = false; REP(i, 2, n + 1) { if (is_prime[i]) { prime[p++] = i; for (int j = 2 * i; j <= n; j += i) is_prime[j] = false; } } } int main() { int n; cin >> n; ll res = 0; sieve(3 * n+10); cnt[prime[0] + prime[1]]++; ex_max = max(ex_max, prime[0] + prime[1]); for (int i = 2; prime[i] <= n; i++) { for (int j = i + 1; prime[j] - prime[i] <= ex_max; j++) { res += cnt[prime[j] - prime[i]]; } for (int j = 0; j < i; j++) { cnt[prime[j] + prime[i]]++; } ex_max = max(ex_max, prime[i] + prime[i - 1]); } cout << res << endl; return 0; }