思路:
我们假设gcd(a, b) = t,然后求,这里技巧性地构造了
,接下来
,然后转化成欧拉函数,接下来找互质即可,
,显然
与
互质,因为
和
互质,提不出公共的约数.此时
.
我们预处理欧拉函数和用埃式筛法预处理每个数的因数,然后枚举n - c的因数t,然后计算即可.
#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define ll long long
// #define double long double
#define ull unsigned long long
#define PII pair<int, int>
#define PDI pair<double, int>
#define PDD pair<double, double>
#define debug(a) cout << #a << " = " << a << endl
#define point(n) cout << fixed << setprecision(n)
#define all(x) (x).begin(), (x).end()
#define mem(x, y) memset((x), (y), sizeof(x))
#define lbt(x) (x & (-x))
#define SZ(x) ((x).size())
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f
namespace nqio{const unsigned R = 4e5, W = 4e5; char *a, *b, i[R], o[W], *c = o, *d = o + W, h[40], *p = h, y; bool s; struct q{void r(char &x){x = a == b && (b = (a = i) + fread(i, 1, R, stdin), a == b) ? -1 : *a++;} void f(){fwrite(o, 1, c - o, stdout); c = o;} ~q(){f();}void w(char x){*c = x;if (++c == d) f();} q &operator >>(char &x){do r(x);while (x <= 32); return *this;} q &operator >>(char *x){do r(*x); while (*x <= 32); while (*x > 32) r(*++x); *x = 0; return *this;} template<typename t> q&operator>>(t &x){for (r(y),s = 0; !isdigit(y); r(y)) s |= y == 45;if (s) for (x = 0; isdigit(y); r(y)) x = x * 10 - (y ^ 48); else for (x = 0; isdigit(y); r(y)) x = x * 10 + (y ^ 48); return *this;} q &operator <<(char x){w(x);return *this;}q &operator<< (char *x){while (*x) w(*x++); return *this;}q &operator <<(const char *x){while (*x) w(*x++); return *this;}template<typename t> q &operator<< (t x) {if (!x) w(48); else if (x < 0) for (w(45); x; x /= 10) *p++ = 48 | -(x % 10); else for (; x; x /= 10) *p++ = 48 | x % 10; while (p != h) w(*--p);return *this;}}qio; }using nqio::qio;
using namespace std;
const int N = 2e5 + 10, MOD = 1e9 + 7;
int n, phi[N], primes[N], cnt, vis[N];
vector<int> factor[N];
void get_euler(int n) {
phi[1] = 1;
for(int i = 2; i <= n; ++ i) {
if(!vis[i]) {
primes[++cnt] = i;
phi[i] = i - 1;
}
for(int j = 1; j <= cnt && i * primes[j] <= n; ++ j) {
vis[i * primes[j]] = true;
if(i % primes[j] == 0) {//最小的质因子
phi[i * primes[j]] = phi[i] * primes[j];
break;
}
phi[i * primes[j]] = phi[i] * (primes[j] - 1);
}
}
phi[1] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j * i <= n; ++j) factor[i * j].emplace_back(j);
}
int lcm(int a, int b) {
return a / __gcd(a, b) * b;
}
signed main() {
get_euler(2e5);
qio >> n;
int ans = 0;
for (int c = 1; c < n; ++c)
for (int t : factor[n - c])
(ans += lcm(c, t) * phi[(n - c) / t]) %= MOD;
qio << ans << "\n";
}