#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[500100]; int prime[500100]; int cnt[500100]; int ex_max = -1; void sieve() { int p = 0; rep(i, 500000)is_prime[i] = true; is_prime[0] = is_prime[1] = false; REP(i, 2, 500000) { if (is_prime[i]) { prime[p++] = i; for (int j = 2 * i; j <= 500000; j += i) is_prime[j] = false; } } } int main() { int n; cin >> n; ll res = 0; sieve(); 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 += (ll)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; }