我是靠谱客的博主 追寻心锁,最近开发中收集的这篇文章主要介绍HDU 6750 Function(莫比乌斯反演)(2020百度之星初赛1),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Function

推式子

S ( n ) = ∑ i = 1 n ∑ d ∣ i d [ g c d ( d , i d ) = = 1 ] = ∑ d = 1 n d ∑ d ∣ i [ g c d ( d , i d ) = = 1 ] = ∑ d = 1 n d ∑ i = 1 n d [ g c d ( d , i ) = = 1 ] = ∑ d = 1 n d ∑ i = 1 n d ∑ k ∣ g c d ( d , i ) μ ( k ) = ∑ k = 1 n μ ( k ) k ∑ d = 1 n k d ∑ i = 1 n k 2 d t = k 2 d = ∑ t = 1 n n t ∑ k 2 ∣ t μ ( k ) k t k 2 = ∑ k = 1 n μ ( k ) k ∑ k 2 ∣ t n t t k 2 i = t k 2 = ∑ k = 1 n μ ( k ) k ∑ i = 1 n k 2 n i k 2 i S(n) = sum_{i = 1} ^{n} sum_{d mid i} d [gcd(d, frac{i}{d}) == 1]\ = sum_{d = 1} ^{n} d sum_{d mid i} [gcd(d, frac{i}{d}) == 1]\ = sum_{d = 1} ^{n}d sum_{i = 1} ^{frac{n}{d}}[gcd(d, i)== 1]\ = sum_{d = 1} ^{n}d sum_{i = 1} ^{frac{n}{d}} sum_{k mid gcd(d, i)} mu(k)\ = sum_{k = 1} ^{n} mu(k) k sum_{d = 1} ^{frac{n}{k}} d sum_{i = 1} ^{frac{n}{k ^2d}}\ t = k ^ 2 d\ = sum_{t = 1} ^{n} frac{n}{t} sum_{k ^ 2 mid t} mu(k)k frac{t}{k ^ 2}\ = sum_{k = 1} ^{sqrt n} mu(k)k sum_{k ^ 2 mid t} frac{n}{t} frac{t}{k ^ 2}\ i = frac{t}{k ^ 2}\ = sum_{k = 1} ^{sqrt n} mu(k) k sum_{i = 1} ^{frac{n}{k ^ 2}} frac{n}{i k ^ 2} i\ S(n)=i=1ndid[gcd(d,di)==1]=d=1nddi[gcd(d,di)==1]=d=1ndi=1dn[gcd(d,i)==1]=d=1ndi=1dnkgcd(d,i)μ(k)=k=1nμ(k)kd=1kndi=1k2dnt=k2d=t=1ntnk2tμ(k)kk2t=k=1n μ(k)kk2ttnk2ti=k2t=k=1n μ(k)ki=1k2nik2ni

代码

注意随手取模,long long × times ×long long会溢出!!!

/*
  Author : lifehappy
*/
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int inf = 0x3f3f3f3f;
const double eps = 1e-7;

const int N = 1e6 + 10, mod = 1e9 + 7, inv2 = mod + 1 >> 1;

int prime[N], cnt;

ll mu[N];

bool st[N];

void init() {
    mu[1] = 1;
    for(int i = 2; i < N; i++) {
        if(!st[i]) {
            prime[cnt++] = i;
            mu[i] = -1;
        }
        for(int j = 0; j < cnt && i * prime[j] < N; j++) {
            st[i * prime[j]] = 1;
            if(i % prime[j] == 0) break;
            mu[i * prime[j]] = -mu[i];
        }
    }
    for(int i = 1; i < N; i++) {
        mu[i] = (mu[i - 1] + 1ll * i * mu[i] % mod + mod) % mod;
    }
}
ll calc1(ll l, ll r) {
    return 1ll * (l + r) % mod * ((r - l + 1) % mod) % mod * inv2 % mod;
}

ll calc2(ll n) {
    ll ans = 0;
    for(ll l = 1, r; l <= n; l = r + 1) {
        r = n / (n / l);
        ans = (ans + 1ll * (n / l) % mod * calc1(l, r) % mod) % mod;
    }
    return ans;
}

int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    init();
    int T;
    scanf("%d", &T);
    while(T--) {
        ll n, ans = 0;
        scanf("%lld", &n);
        int m = sqrt(n);
        for(ll l = 1, r; l <= m; l = r + 1) {
            r = min((int)sqrt(n / (n / (l * l))), m);
            ans = (ans + 1ll * ((mu[r] - mu[l - 1]) % mod + mod) % mod * calc2(n / (l * l)) % mod) % mod;
        }
        printf("%lldn", ans);
    }
	return 0;
}

最后

以上就是追寻心锁为你收集整理的HDU 6750 Function(莫比乌斯反演)(2020百度之星初赛1)的全部内容,希望文章能够帮你解决HDU 6750 Function(莫比乌斯反演)(2020百度之星初赛1)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部