#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b makePrimes(int n) { // [2,n] vector res, pr(n + 1, 1); pr[0] = pr[1] = 0; rep(p, 2, sqrt(n) + 2) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0; rep(p, 2, n + 1) if (pr[p]) res.push_back(p); return res; } vector makePrimesBool(int n) { // [2,n] vector pr(n + 1, 1); pr[0] = pr[1] = 0; rep(p, 2, sqrt(n) + 2) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0; return pr; } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N; M = sqrt(2 * N) + 5; auto vp_n = makePrimes(N); auto vp_m = makePrimes(M); auto vpb_n = makePrimesBool(N); int ans = 0; fore(p, vp_n) fore(r, vp_m) if(p <= N and r <= N) { int q = r * r - p; if (0 <= q and vpb_n[q] and q <= N) ans++; } cout << ans << endl; }