longlong n; int M; std::vector<longlong> pre, suc; std::vector<int> primes;
inlinelonglongrec(longlong res, int last, longlong mul){ longlong t = (res > M ? suc[n / res] : pre[res]) - pre[primes[last] - 1]; longlong ret = mul * -t; for (int i = last, p; i < (int)primes.size(); i++) { p = primes[i]; if ((longlong)p * p > res) break; ret += rec(res / p, i + 1, -mul); } return ret; }
inlinelonglongsolve(constlonglong n){ pre.clear(); suc.clear(); primes.clear(); M = sqrt(n); pre.resize(M + 1); suc.resize(M + 1); for (int i = 1; i <= M; i++) { pre[i] = i - 1; suc[i] = n / i - 1; } for (int p = 2, end; p <= M; p++) { if (pre[p] == pre[p - 1]) continue; primes.push_back(p); constlonglong pcnt = pre[p - 1], q = (longlong)p * p, m = n / p; end = std::min<longlong>(M, n / q); for (int i = 1, w = M / p; i <= w; i++) suc[i] -= suc[i * p] - pcnt; for (int i = M / p + 1; i <= end; i++) suc[i] -= pre[m / i] - pcnt; for (int i = M; i >= q; i--) pre[i] -= pre[i / p] - pcnt; } primes.push_back(M + 1); return n > 1 ? 1 + rec(n, 0, 1) : 1; }
longlong n; int M; std::vector<int> pre[2], suc[2], primes;
inlineintdec(constint x, constint v){ return x - v < 0 ? x - v + MOD : x - v; } inlineintadd(constint x, constint v){ return x + v >= MOD ? x + v - MOD : x + v; }
inlineintrec(longlong res, int last, int mul){ int t = dec((res > M ? suc[1][n / res] : pre[1][res]), pre[1][primes[last] - 1]); int ret = (longlong)mul * t % MOD; for (int i = last, p; i < (int)primes.size(); i++) { p = primes[i]; if ((longlong)p * p > res) break; for (longlong q = p, nres = res, nmul = mul * (p - 1ll) % MOD; p * q <= res; q *= p) { ret = add(ret, rec(nres /= p, i + 1, nmul)); nmul = nmul * p % MOD; ret = add(ret, nmul); } } return ret; }
inlineintsolve(constlonglong n){ M = sqrt(n); pre[0].clear(); pre[1].clear(); suc[0].clear(); suc[1].clear(); primes.clear(); pre[0].resize(M + 1); pre[1].resize(M + 1); suc[0].resize(M + 1); suc[1].resize(M + 1); for (int i = 1, t; i <= M; i++) { pre[0][i] = i - 1; pre[1][i] = ((i * (i + 1ll)) / 2 - 1 + MOD) % MOD; t = (n / i) % MOD; suc[0][i] = t - 1; suc[1][i] = ((t * (t + 1ll)) / 2 - 1 + MOD) % MOD; } for (int p = 2, end; p <= M; p++) { if (pre[0][p] == pre[0][p - 1]) continue; primes.push_back(p); constlonglong q = (longlong)p * p, m = n / p; constint pcnt = pre[0][p - 1], psum = pre[1][p - 1]; end = std::min<longlong>(M, n / q); for (int i = 1, w = M / p; i <= w; i++) { suc[0][i] = dec(suc[0][i], dec(suc[0][i * p], pcnt)); suc[1][i] = dec(suc[1][i], dec(suc[1][i * p], psum) * (longlong)p % MOD); } for (int i = M / p + 1; i <= end; i++) { suc[0][i] = dec(suc[0][i], dec(pre[0][m / i], pcnt)); suc[1][i] = dec(suc[1][i], dec(pre[1][m / i], psum) * (longlong)p % MOD); } for (int i = M; i >= q; i--) { pre[0][i] = dec(pre[0][i], dec(pre[0][i / p], pcnt)); pre[1][i] = dec(pre[1][i], dec(pre[1][i / p], psum) * (longlong)p % MOD); } } primes.push_back(M + 1); for (int i = 1; i <= M; i++) { pre[1][i] = dec(pre[1][i], pre[0][i]); suc[1][i] = dec(suc[1][i], suc[0][i]); } return n > 1 ? add(1, rec(n, 0, 1)) : 1; }