#include using namespace std; #include using namespace atcoder; // using mint = modint998244353; using mint = modint1000000007; //define using ll = long long; using ull = unsigned long long; #define rep(i,l,r) for (int i = (int)(l); i < (int)(r); i++) #define len(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define inf (long long)1<<60 #define mod (long long)998244353 template void chmin(T& a, T b) { if (a > b) a = b; } template void chmax(T& a, T b) { if (a < b) a = b; } template using spq = priority_queue, greater>; //scan inline void scan() {} inline void scan(int &a) { std::cin >> a; } inline void scan(unsigned &a) { std::cin >> a; } inline void scan(long &a) { std::cin >> a; } inline void scan(long long &a) { std::cin >> a; } inline void scan(unsigned long long &a) { std::cin >> a; } inline void scan(char &a) { std::cin >> a; } inline void scan(float &a) { std::cin >> a; } inline void scan(double &a) { std::cin >> a; } inline void scan(long double &a) { std::cin >> a; } inline void scan(std::vector &vec) { for (int32_t i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } } inline void scan(std::string &a) { std::cin >> a; } template inline void scan(std::vector &vec); template inline void scan(std::array &vec); template inline void scan(std::pair &p); template inline void scan(T (&vec)[size]); template inline void scan(std::vector &vec) { for (auto &i : vec) scan(i); } template inline void scan(std::deque &vec) { for (auto &i : vec) scan(i); } template inline void scan(std::array &vec) { for (auto &i : vec) scan(i); } template inline void scan(std::pair &p) { scan(p.first); scan(p.second); } template inline void scan(T (&vec)[size]) { for (auto &i : vec) scan(i); } template inline void scan(T &a) { std::cin >> a; } inline void in() {} template inline void in(Head &head, Tail &...tail) { scan(head); in(tail...); } //print inline void print() { std::cout << ' '; } inline void print(const bool &a) { std::cout << a; } inline void print(const int &a) { std::cout << a; } inline void print(const unsigned &a) { std::cout << a; } inline void print(const long &a) { std::cout << a; } inline void print(const long long &a) { std::cout << a; } inline void print(const unsigned long long &a) { std::cout << a; } inline void print(const char &a) { std::cout << a; } inline void print(const char a[]) { std::cout << a; } inline void print(const float &a) { std::cout << a; } inline void print(const double &a) { std::cout << a; } inline void print(const long double &a) { std::cout << a; } inline void print(const std::string &a) { for (auto &&i : a) print(i); } template inline void print(const std::vector &vec); template inline void print(const std::array &vec); template inline void print(const std::pair &p); template inline void print(const T (&vec)[size]); template inline void print(const std::vector &vec) { if (vec.empty()) return; print(vec[0]); for (auto i = vec.begin(); ++i != vec.end();) { std::cout << ' '; print(*i); } } template inline void print(const std::deque &vec) { if (vec.empty()) return; print(vec[0]); for (auto i = vec.begin(); ++i != vec.end();) { std::cout << ' '; print(*i); } } template inline void print(const std::array &vec) { print(vec[0]); for (auto i = vec.begin(); ++i != vec.end();) { std::cout << ' '; print(*i); } } template inline void print(const std::pair &p) { print(p.first); std::cout << ' '; print(p.second); } template inline void print(const T (&vec)[size]) { print(vec[0]); for (auto i = vec; ++i != end(vec);) { std::cout << ' '; print(*i); } } template inline void print(const T &a) { std::cout << a; } inline void out() { std::cout << '\n'; } template inline void out(const T &t) { print(t); std::cout << '\n'; } template inline void out(const Head &head, const Tail &...tail) { print(head); std::cout << ' '; out(tail...); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); } } iosetup; // 再帰を用いて積が x 以下のものを列挙 void generate_products(const vector& fp, ll l, ll x, ll idx, ll current_product, ll count, vector& results) { // l 個選んだ場合、積を結果に追加 if (count == l) { results.push_back(current_product); return; } for (ll i = idx; i < fp.size(); ++i) { ll next_product = current_product * fp[i]; // 積が x を超える場合、以降のループをスキップ if (next_product > x) { break; } // 再帰で次の要素を選択 generate_products(fp, l, x, i + 1, next_product, count + 1, results); } } // l 個選んだ部分集合の積を生成し、積が x 以下のもののみを列挙 vector generate_valid_products(const vector& fp, ll l, ll x) { vector results; generate_products(fp, l, x, 0, 1, 0, results); return results; } ll calc(ll x, vector fp) { ll res = x; ll l = 1; while (l <= (ll)fp.size()) { ll tmp = 1; for (ll i = 0; i < l - 1; ++i) { tmp *= fp[i]; } while (!fp.empty() && tmp * fp.back() > x) { fp.pop_back(); if ((ll)fp.size() < l) { return res; } } auto results = generate_valid_products(fp, l, x); for (ll product : results) { if (l%2){ res -= x/product; }else{ res += x/product; } } ++l; } return res; } int main() { ll n; cin >> n; ll rootn = static_cast(sqrt(n)); vector minp(rootn + 1, 0); // 素因数の前計算 for (ll i = 3; i <= rootn; i += 2) { if (minp[i] != 0) continue; for (ll j = i; j <= rootn; j += i) { if (minp[j] == 0) { minp[j] = i; } } } ll ans = 0; const ll const_limit = 3000; // p の全探索 for (ll p = 2; p <= rootn; ++p) { vector fp; ll p_ = p; while (minp[p_] != 0) { ll mp = minp[p_]; fp.push_back(mp); while (p_ % mp == 0) { p_ /= mp; } } // q は奇数 // p < q < 2p // max の値は m 以下 ll m = n / (2 * p); ll lq = 2 * ((p + 1) / 2) + 1; ll rq = min(m + 1, 2 * p); if (rq - lq <= const_limit) { for (ll r = lq; r < rq; r += 2) { if (!(0 < r - p && r - p < p)) continue; bool divisible = false; for (ll i : fp) { if (r % i == 0) { divisible = true; break; } } if (!divisible) { ans += m / r; // この倍数まで大丈夫 } } } else { // この時あきらかに const_limit <= lq ll olq = lq, orq = rq; for (ll res = max(m / orq, 1LL); res <= m / olq; ++res) { lq = m / (res + 1); rq = m / res; lq = max(lq, olq - 1); rq = min(rq, orq - 1); if (lq >= rq) continue; vector fp_ = fp; fp_.insert(fp_.begin(), 2); // 2を追加 while (!fp_.empty() && fp_.back() > rq) { fp_.pop_back(); } ll cnt = calc(rq, fp_) - calc(lq, fp_); ans += cnt * res; } } } cout << ans << endl; return 0; }