• 欧拉函数和莫比乌斯函数


    多校赛上最近有道题目是gugufishtion

    Problem Description

    Today XianYu is too busy with his homework, but the boring GuGu is still disturbing him!!!!!! At the break time, an evil idea arises in XianYu’s mind. ‘Come on, you xxxxxxx little guy.’ ‘I will give you a function ϕ(x) which counts the positive integers up to x that are relatively prime to x.’ ‘And now I give you a fishtion, which named GuGu Fishtion, in memory of a great guy named XianYu and a disturbing and pitiful guy GuGu who will be cooked without solving my problem in 5 hours.’ ‘The given fishtion is defined as follow:

     

    Gu(a,b)=ϕ(ab)ϕ(a)ϕ(b)Gu(a,b)=ϕ(ab)ϕ(a)ϕ(b)


    And now you, the xxxxxxx little guy, have to solve the problem below given m,n,p. 

    (∑a=1m∑b=1nGu(a,b)(modp)(∑a=1m∑b=1nGu(a,b)(modp)


    So SMART and KINDHEARTED you are, so could you please help GuGu to solve this problem? ‘GU GU!’ GuGu thanks.

    这里写图片描述

    看题解的时候看到这个通过观察,感到十分崩溃

    后来发现原来这个φ 是欧拉函数

    欧拉函数,就是求小于n的与n互质的数的数目

    通式是:

    其中p1, p2……pn为x的所有质因数,x是不为0的整数。

    φ(1)=1(和1互质的数(小于等于1)就是1本身)。

    注意:每种质因数只一个。 比如12=2*2*3那么φ(12)=12*(1-1/2)*(1-1/3)=4

    若n是质数p的k次幂,

      

    ,因为除了p的倍数外,其他数都跟n互质。

    设n为正整数,以 φ(n)表示不超过n且与n互素的正整数的个数,称为n的欧拉函数值

    φ:N→N,n→φ(n)称为欧拉函数。

    欧拉函数是积性函数——若m,n互质,

     

    特殊性质:当n为奇数时,

      

    , 证明与上述类似。

    若n为质数则

     

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    /*

    特性 :

    1.若a为质数,phi[a]=a-1;

    2.若a为质数,b mod a=0,phi[a*b]=phi[b]*a

    3.若a,b互质,phi[a*b]=phi[a]*phi[b](当a为质数时,if b mod a!=0 ,phi[a*b]=phi[a]*phi[b])

    */

    int m[n],phi[n],p[n],nump;

    //m[i]标记i是否为素数,0为素数,1不为素数;p是存放素数的数组;nump是当前素数个数;phi[i]为欧拉函数

    int make()

    {

            phi[1]=1;

        for (int i=2;i<=n;i++)

        {

            if (!m[i])//i为素数

            {

                p[++nump]=i;//将i加入素数数组p中

                phi[i]=i-1;//因为i是素数,由特性得知    

            }    

            for (int j=1;j<=nump&&p[j]*i<n;j++)  //用当前已的到的素数数组p筛,筛去p[j]*i

            {

                m[p[j]*i]=1;//可以确定i*p[j]不是素数 

                if (i%p[j]==0) //看p[j]是否是i的约数,因为素数p[j],等于判断i和p[j]是否互质 

                {

                    phi[p[j]*i]=phi[i]*p[j]; //特性2

                    break;

                }

                else phi[p[j]*i]=phi[i]*(p[j]-1); //互质,特性3其,p[j]-1就是phi[p[j]]   

            }

        }

    }

    莫比乌斯(Möbius)函数

      对于每个正整数n(n ≥ 2),设它的质因数分解式为:

      

      根据这个式子定义n的莫比乌斯函数为:

      

      也就是如果n有平方因子,则为0. 否则是-1的质因数个数次方。

      举个简单的例子:6 = 2 × 3,所以;  9 = 3×3, 所以 

    【命题一】

      对于正整数n有:

      

      也就是n>2时,所有n的约数对应函数值之和为0.

    莫比乌斯反演

      若定义在正整数集上的两个函数,f(n)和g(n)满足对任意n有:

            (1)

      

      则可以通过f来表示g:

          (2)

      反之,亦可以由关系(2)得到(1)

    莫比乌斯函数和欧拉函数的关系:

      

  • 相关阅读:
    《架构真经》读后感2
    css的引入
    交流会发言
    css学习
    数据结构-哈希表、二叉排序数
    软工人学习日常
    Java包、类、方法、变量、常量命名规范
    数据库命名规范
    学生信息系统jsp界面
    学生信息系统servlet层
  • 原文地址:https://www.cnblogs.com/wyboooo/p/9643390.html
Copyright © 2020-2023  润新知