Battlestation Operational
∑i=1n∑j=1i⌈ij⌉[gcd(i,j)=1]∑i=1n∑j=1i(ij+1)[gcd(i,j)=1]−∑i=1n∑j=1i[gcd(i,j)=1,j∣i]∑i=1n∑j=1i(ij+1)[gcd(i,j)=1]−n∑i=1n∑j=1iij[gcd(i,j)=1]+∑i=1n∑j=1i[gcd(i,j)=1]−n∑i=1n∑j=1iij[gcd(i,j)=1]+∑i=1ϕ(i)−n∑i=1n∑j=1iij[gcd(i,j)=1]∑d=1nμ(d)∑i=1nd∑j=1iij求解∑i=1n∑j=1iij=∑i=1n∑j=inji可以发现这个东西具有区间分块性质所以可以利用差分然后求前缀和得到,具体实现看代码整体复杂度O(nlogn+T×n)\sum_{i = 1} ^{n} \sum_{j = 1} ^{i} \lceil \frac{i}{j} \rceil [gcd(i, j) = 1]\\ \sum_{i = 1} ^{n} \sum_{j = 1} ^{i}( \frac{i}{j} + 1)[gcd(i, j) = 1] - \sum_{i = 1} ^{n}\sum_{j = 1} ^{i}[gcd(i, j) = 1, j \mid i]\\ \sum_{i = 1} ^{n} \sum_{j = 1} ^{i}(\frac{i}{j} + 1)[gcd(i, j) = 1] - n\\ \sum_{i = 1} ^{n} \sum_{j = 1} ^{i} \frac{i}{j}[gcd(i, j) = 1] + \sum_{i = 1} ^{n} \sum_{j = 1} ^{i} [gcd(i, j) = 1] - n\\ \sum_{i = 1} ^{n} \sum_{j = 1} ^{i} \frac{i}{j}[gcd(i, j) = 1] + \sum_{i = 1} \phi(i) - n\\ \sum_{i = 1} ^{n} \sum_{j = 1} ^{i} \frac{i}{j}[gcd(i, j)= 1]\\ \sum_{d = 1} ^{n} \mu(d) \sum_{i = 1} ^{\frac{n}{d}} \sum_{j = 1} ^{i} \frac{i}{j}\\ 求解\sum_{i = 1} ^{n} \sum_{j = 1} ^{i} \frac{i}{j} = \sum_{i = 1} ^{n} \sum_{j = i} ^{n} \frac{j}{i}\\ 可以发现这个东西具有区间分块性质\\所以可以利用差分然后求前缀和得到,具体实现看代码\\ 整体复杂度O(n \log n + T \times \sqrt n)\\ i=1∑nj=1∑i⌈ji⌉[gcd(i,j)=1]i=1∑nj=1∑i(ji+1)[gcd(i,j)=1]−i=1∑nj=1∑i[gcd(i,j)=1,j∣i]i=1∑nj=1∑i(ji+1)[gcd(i,j)=1]−ni=1∑nj=1∑iji[gcd(i,j)=1]+i=1∑nj=1∑i[gcd(i,j)=1]−ni=1∑nj=1∑iji[gcd(i,j)=1]+i=1∑ϕ(i)−ni=1∑nj=1∑iji[gcd(i,j)=1]d=1∑nμ(d)i=1∑dnj=1∑iji求解i=1∑nj=1∑iji=i=1∑nj=i∑nij可以发现这个东西具有区间分块性质所以可以利用差分然后求前缀和得到,具体实现看代码整体复杂度O(nlogn+T×n)
/*Author : lifehappy
*/
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 1e6 + 10, mod = 1e9 + 7;int prime[N], phi[N], mu[N], f[N], cnt, n;bool st[N];void init() {mu[1] = phi[1] = 1;for(int i = 2; i < N; i++) {if(!st[i]) {prime[++cnt] = i;mu[i] = -1;phi[i] = i - 1;}for(int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) {st[i * prime[j]] = 1;if(i % prime[j] == 0) {phi[i * prime[j]] = phi[i] * prime[j];break;}phi[i * prime[j]] = phi[i] * (prime[j] - 1);mu[i * prime[j]] = -mu[i];}}for(int i = 1; i < N; i++) {for(int j = i; j < N; j += i) {int l = j, r = j + i;f[l] = (f[l] + (j / i)) % mod;if(r < N) f[r] = (f[r] - (j / i) + mod) % mod;}}for(int i = 1; i < N; i++) {phi[i] = (phi[i] + phi[i - 1]) % mod;mu[i] = (mu[i] + mu[i - 1] + mod) % mod;f[i] = (f[i] + f[i - 1]) % mod;}for(int i = 1; i < N; i++) {f[i] = (f[i] + f[i - 1]) % mod;}
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);init();while(scanf("%d", &n) != EOF) {ll ans = 0;for(int l = 1, r; l <= n; l = r + 1) {r = n / (n / l);ans = (ans + 1ll * (mu[r] - mu[l - 1]) * f[n / l] % mod + mod) % mod;}ans = (ans + phi[n] - n + mod) % mod;printf("%lld\n", ans);}return 0;
}