2020HDU多校第六场 A Very Easy Math Problem 莫比乌斯反演

传送门

计算过程:#

S(n)=a1=1na2=1nan=1n(j=1xajk)=a1=1na1ka2=1na2kan=1nank=(i=1nik)x

a1=1na2=1nan=1n(j=1xajk)f(gcd(a1,a2,,an))gcd(a1,a2,,an)

=d=1ndf(d)S(n)[gcd(a1,a2,,an)=d]

=d=1ndf(d)S(nd)[gcd(a1,a2,,an)=1]dkx

=d=1ndkx+1f(d)S(nd)[gcd(a1,a2,,an)=1]

=d=1ndkx+1f(d)S(nd)t|gcd(a1,a2,,an)μ(t)

枚举t

=d=1ndkx+1f(d)t=1ndμ(t)tkx(i=1ndtik)x

=d=1ndkx+1f(d)t=1ndμ(t)tkxS(ndt)

T=dt

T=1nS(nT)d|Tdkx+1(Td)kxμ(Td)f(d)

T=1nS(nT)d|Tdkx+1(Td)kxμ(Td)f(d)

T=1nS(nT)d|TdTkxμ(Td)f(d)

具体实现#

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
/* freopen("k.in", "r", stdin);
freopen("k.out", "w", stdout); */
// clock_t c1 = clock();
// std::cerr << "Time:" << clock() - c1 <<"ms" << std::endl;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define de(a) cout << #a << " = " << a << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define ls ((x) << 1)
#define rs ((x) << 1 + 1)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
#define inf 0x3f3f3f3f
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MAXN = 2e5 + 7;
const ll MAXM = 4e5 + 7;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
const double pi = acos(-1.0);
ll k, x;
ll quick_pow(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (1LL * ans * a) % MOD;
        a = (1LL * a * a) % MOD;
        b >>= 1;
    }
    return ans;
}
ll mu[MAXN], pri[MAXN], vis[MAXN], tot = 0;
ll sum[MAXN];
void init()
{
    mu[1] = 1;
    for (int i = 2; i < MAXN; i++)
    {
        if (!vis[i])
            pri[++tot] = i, mu[i] = -1;
        for (int j = 1; j <= tot && pri[j] * i < MAXN; j++)
        {
            vis[i * pri[j]] = 1;
            if (i % pri[j] == 0)
                mu[i * pri[j]] = 0;
            else
                mu[i * pri[j]] = -mu[i];
        }
    }
    for (int i = 1; i < MAXN; i++)
        sum[i] = sum[i - 1] + mu[i];
}
ll f[MAXN];
void calf()
{
    for (int i = 0; i < MAXN; i++)
        f[i] = 1;
    for (ll i = 2; i * i < MAXN; i++)
        for (ll j = 1; j * i * i < MAXN; j++)
            f[j * i * i] = 0;
}
ll s[MAXN] = {0};
void cals()
{
    ll now = 0;
    for (ll i = 1; i < MAXN; i++)
    {
        (now += quick_pow(i, k)) %= MOD;
        s[i] = quick_pow(now, x);
    }
}
ll g[MAXN] = {0};
ll sumg[MAXN] = {0};
void calg()
{
    for (ll d = 1; d < MAXN; d++)
        for (ll t = 1; t * d < MAXN; t++)
        {
            ll temp = (d * mu[t]) % MOD * f[d] % MOD;
            (g[t * d] += temp % MOD) %= MOD;
        }
    for (int i = 1; i < MAXN; i++)
        (sumg[i] = sumg[i - 1] + g[i] * quick_pow(i, k * x)) %= MOD;
}
int main()
{
    int t;
    scanf("%d%lld%lld", &t, &k, &x);
    init(), calf(), cals(), calg();
    while (t--)
    {
        ll n;
        scanf("%lld", &n);
        ll ans = 0;
        for (ll l = 1, r; l <= n; l = r + 1)
        {
            r = n / (n / l);
            ll temp = s[n / l];
            (temp *= (sumg[r] - sumg[l - 1])) %= MOD;
            (temp += MOD) %= MOD;
            (ans += temp) %= MOD;
        }
        printf("%lld\n", (ans % MOD + MOD) % MOD);
    }
    return 0;
}
posted @   GrayKido  阅读(269)  评论(0编辑  收藏  举报
编辑推荐:
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
阅读排行:
· Spring AI + Ollama 实现 deepseek-r1 的API服务和调用
· 《HelloGitHub》第 106 期
· 数据库服务器 SQL Server 版本升级公告
· 深入理解Mybatis分库分表执行原理
· 使用 Dify + LLM 构建精确任务处理应用
点击右上角即可分享
微信分享提示
主题色彩