• 莫比乌斯反演-学习笔记


    注意莫比乌斯反演的本质上是在分解质因数并进行容斥,

    但与一般容斥的不同之处在,其可以借助筛法等原理,实现快速构造出一个数列。

    而容斥只能一个一个数的慢慢地算。

     注意只有n->oo  时,f(x)=0时才可以用形式2

     性质与技巧:

    1,利用分解素因数计算积性函数

    所以可以先预处理好所以质数的k次方,然后利用筛法,快速计算记性函数

    2.莫比乌斯反演保持积性

    代码:

    1.求莫比乌斯函数

    #include <cstdio>
    #include <cstring>
    using namespace std;
    const int maxn = 1000000+5;
    bool vis[maxn];
    int prime[maxn],primes,mu[maxn],f[maxn];
    int main()
    {
        memset(vis,0,sizeof(vis));
        mu[1]=1;
        primes=0;
        for(int i=2; i<maxn; i++)
        {
            if(!vis[i])
            {
                prime[primes++]=i;
                mu[i]=-1;
            }
            for(int j=0; j<primes&&i*prime[j]<maxn; ///只添加到最小素因素为止,以保证状态转移的路径是唯一的
            {
                vis[i*prime[j]]=1;
                if(i%prime[j]) mu[i*prime[j]]=-mu[i];
                else///出现最小素因数
                {
                    mu[i*prime[j]]=0;
                    break;
                }
            }
        }
    

     简单我就不列了(因为懒),这里列一个经典难题

    http://acm.hdu.edu.cn/showproblem.php?pid=6134

    我写的详细题解如下

    https://wenku.baidu.com/view/1a46ad3c182e453610661ed9ad51f01dc281572e

  • 相关阅读:
    Bullet 学习笔记之 btPersistentManifold 及 btManifoldPoint
    Bullet 学习笔记之 btCollisionWorld::performDiscreteCollisionDetection
    Bullet 学习笔记之 btCollisionWorld
    hdu 6617
    codeforces 1247 E
    GYM 101174 A
    GYM 100714 G
    codeforces 1239 C
    牛客挑战赛33D
    codeforces 1238 E
  • 原文地址:https://www.cnblogs.com/qswg/p/6870323.html
Copyright © 2020-2023  润新知