#include using namespace std; using ll = long long; #define rep(i,m,n) for(int i=m; i bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; } template bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; } template T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; } template T lcm(T a, T b){ return a / gcd(a, b) * b; } struct Eratosthenes{ vector is_prime; vector prime_list; vector spf; Eratosthenes(int N) : is_prime(N+1, true), spf(N+1, -1) { is_prime[1] = false; spf[1] = 1; for(int p = 2; p <= N; ++p){ if(!is_prime[p]) continue; prime_list.push_back(p); spf[p] = p; for(int q = p+p; q <= N; q += p){ is_prime[q] = false; if(spf[q] == -1) spf[q] = p; } } } vector> prime_factrize(int n){ vector> res; while(n > 1){ int p = spf[n], ex = 0; while(n % p == 0){ n /= p; ++ex; } res.push_back({p, ex}); } return res; } vector divisors(int n){ vector res({1}); auto pf = prime_factrize(n); for(auto p : pf){ int sz = res.size(); for(int i = 0; i < sz; ++i){ int v = 1; for(int j = 0; j < p.second; ++j){ v *= p.first; res.push_back(res[i] * v); } } } // sort(res.begin(), res.end()) return res; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; Eratosthenes Era(N); vector plist = Era.prime_list; vector isp = Era.is_prime; int n = plist.size(); ll ans = 0LL; if(n <= 100){ rep(i, 0, n) rep(j, 0, n) rep(k, 0, n){ if(plist[i] + plist[j] + 0LL == plist[k]*plist[k]*1LL) ++ans; } cout << ans << endl; }else{ ++ans; // (p,q,r) = (2,2,2) // r > 2より,r*rは必ず奇数 よって,pかqのどちらか一方は必ず偶数(2) rep(i, 1, n){ ll r = plist[i]; if(r*r - 2LL > ll(N)) break; if(isp[r*r - 2LL]) ans += 2LL; } cout << ans << endl; } return 0; }