求有多少方案使得 a,b,c,d 满足 a^b=c^d, 1\leq a,b,c,d \leq n,结果对 10^9+7 取模
可以将 a,c 的取值分为以下三种情况:
最后,再将三种情况算得方案数相加。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
ll n;
ll range;
int f[100010];
ll gcd(ll x, ll y) {
return y == 0 ? x : gcd(y, x % y);
}
ll lcm(ll x, ll y) {
return x * y / gcd(x, y);
}
void solve() {
cin >> n;
range = sqrt(n);
ll ans = 0;
for (ll i = 2; i <= range; i++) {
if (f[i] == 0) {
for (ll j = 1; 1; j++) {
ll tmp = qpow(i, j);
if (tmp <= range) {
f[tmp] = 1;
}
if (tmp > n) break;
for (ll k = 1; k < j; k++) {
ans += n / (lcm(j, k) / min(j, k)) * 2;
ans %= mod;
}
}
}
}
cout << (ans + (n - 1) * n % mod + n * n % mod) % mod << '\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}