The meaning of problems
Request $ f (n, a, b) = \ sum_ {i = 1} ^ n \ sum_ {j = 1} ^ i gcd (i ^ aj ^ a, i ^ bj ^ b) [gcd (i, j) = 1] \% (10 ^ 9 + 7) $, $ 1 \ le n, a, b \ le 10 ^ 9 $, a total of $ T $ group test, only 10 sets of $ n-$ greater than $ 10 ^ 6 $.
analysis
First, when $ i, j $ coprime, $ a, b $ coprime with $ gcd (i ^ aj ^ a , you ^ bj ^ b) = ij $ ( proof see links ), can also play table guess Well a guess.
Can be introduced: $$ \ sum_ {d = 1} ^ {N} \ mu (d) \ cdot d \ sum_ {i = 1} ^ {\ lfloor \ frac {N} {d} \ rfloor} \ sum_ {j = 1} ^ {i} (ij) $$
Consider the latter part alone, $ \ sum_ {i = 1} ^ {k} \ sum_ {j = 1} ^ {i} (ij) = \ frac {k ^ 3-k} {6} $.
Then, only the left side of $ \ mu (d) \ cdot d $,
It with the identity function $ Id (n) = n $ Dirichlet convolution to give
$$\begin{align*}
(\mu(d)\cdot d)*Id(d)
& = \sum_{d|n}(\mu(d)\cdot d)\cdot Id(\frac{n}{d})\\
& = \sum_{d|n}\mu(d) = [n=1]
\end{align*}$$
The next set of Du teach sieved formula
$$\begin{align*}
S(n)
& = \sum\limits_{i=1}^n [i=1]-\sum\limits_{i=2}^ni\cdot S(\lfloor\dfrac{n}{i}\rfloor)\\
& = 1-\sum\limits_{i=2}^ni\cdot S(\lfloor\dfrac{n}{i}\rfloor)
\end{align*}$$
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 6e6 + 10; const ll mod = 1e9+7; const ll inv6 = 166666668; int sum[maxn], mu[maxn], pri[maxn], pn; bool vis[maxn]; map<int, int>mp_sum; int n, a, b; ll s2(ll i, ll j) { return (i+j) * (j-i+1) / 2 % mod; } ll s3(ll k) { return (k*k%mod - 1) * k % mod * inv6 % mod; } ll S(ll x) { if(x < maxn) return sum[x]; if(mp_sum[x]) return mp_sum[x]; ll ret = 1LL; for(int i = 2, j;i <= x;i = j+1) { j = x / (x / i); ret = (ret - s2(i, j) * (S(x/i))%mod) % mod; } return mp_sum[x] = (ret + mod) % mod; } void pre() { mu[1] = 1; for(int i = 2;i < maxn;i++) { if(!vis[i]) { pri[++pn] = i; mu[i] = -1; } for(int j = 1;j <= pn && i * pri[j] < maxn; j++) { vis[i * pri[j]] = true; if(i % pri[j]) mu[i * pri[j]] = -mu[i]; else { mu[i * pri[j]] = 0; break; } } } for(int i = 1;i < maxn;i++) sum[i] = (sum[i-1] + i * mu[i]) % mod; } int main() { pre(); int T; scanf("%d", &T); while(T--) { scanf("%d%d%d", &n, &a, &b); ll ans = 0; for(ll l = 1,r; l <= n;l = r+1) { r = n / (n / l); ans = (ans + (S(r) - S(l-1)) * s3(n/l)) % mod; } printf("%lld\n", (ans+mod)%mod); } return 0; }
Initially opened MAXN = 2e6, will TLE; original blog open 6e6, and MLE, a long long int array into the job.
A standard is actually pushed into $ \ displaystyle ans = \ frac {\ sum _ {i = 1} ^ ni \ varphi (i) - 1} {2} $, less a divisible block.
However, through this solution, I deeply understand the temporal and spatial contradictions Du taught how to balance screen.
Reference Links: https://segmentfault.com/a/119000002017183