1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #include <cstdio> #include <cmath> using namespace std; template <class Type> void read (Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0'; flag && (x = ~x + 1); } template <class Type, class ...rest> void read (Type &x, rest &...y) { read(x), read(y...); } template <class Type> void write (Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar('0' + x % 10); } typedef long long LL; const int N = 2e5 + 10, mod = 1e9 + 7; bool vis[N]; LL n, w[N]; int B, tot, f[N], g[N], sg[N]; int cnt, p[N], id1[N], id2[N]; void init () { vis[1] = true; for (int i = 2; i < N; ++i) { if (!vis[i]) p[++cnt] = i; for (int j = 1; j <= cnt && i * p[j] < N; ++j) { vis[i * p[j]] = true; if (i % p[j] == 0) break; } } } int &id (LL x) { return x <= B ? id1[x] : id2[n / x]; } void solve () { for (int i = 1; i <= cnt; ++i) { g[i] ; sg[i] = (sg[i - 1] + g[i]) % mod; } for (int i = 1; i <= tot; ++i) f[i] ; for (int i = 1; i <= cnt && p[i] <= B; ++i) for (int j = 1; j <= tot && w[j] >= (LL)p[i] * p[i]; ++j) f[j] = (f[j] - (LL)g[i] * (f[id(w[j] / p[i])] - sg[i - 1])) % mod; } int S (LL a, int b) { if (p[b] >= a) return 0; int res = (f[id(a)] - sg[b]) % mod; for (int i = b + 1; i <= cnt && (LL)p[i] * p[i] <= a; ++i) { LL t = p[i]; for (int k = 1; t <= a; ++k, t *= p[i]) res = (res + (S(a / t, i) + (k > 1))) % mod; } return res; } int main () { init(); read(n); B = sqrt(n); for (LL l = 1, r; l <= n; l = r + 1) { r = n / (n / l); w[id(n / l) = ++tot] = n / l; } solve(); for (int i = 1; i <= cnt; ++i) sg[i] = ((LL)sg[i - 1] ) % mod; write((S(n, 0) + mod) % mod); return 0; }
|