当前位置:网站首页>Integral function and Dirichlet convolution
Integral function and Dirichlet convolution
2022-04-23 09:42:00 【Zimba_】
Preface :
Early to bed and early to rise makes a man healthy,wealthy and wise. ! Today, let's talk about the integral function .
Definition of product function :
What is an integral function ?( Also called multiplicative function )
Let's start with a broader concept , Arithmetic functions .( Arithmetic function Number theoretic functions )
Arithmetic functions , Is a function defined for all positive integers , That is, a function whose domain is a positive integer .
and Integrability function , Is a special arithmetic function .
For the function f ( x ) f(x) f(x),
If meet f ( 1 ) = 1 f(1)=1 f(1)=1,
And for any coprime positive integer p p p and q q q, Satisfy f ( p q ) = f ( p ) f ( q ) f(pq)=f(p)f(q) f(pq)=f(p)f(q),
said f ( x ) f(x) f(x) It's a product function .
And for functions f ( x ) f(x) f(x),
If meet f ( 1 ) = 1 f(1)=1 f(1)=1,
And for any positive integer p p p and q q q, Satisfy f ( p q ) = f ( p ) f ( q ) f(pq)=f(p)f(q) f(pq)=f(p)f(q),
said f ( x ) f(x) f(x) Is a completely integrable function .
( That's not what we're talking about here )
Let's focus on the integral function , Now let's move on to this definition .
According to the unique decomposition theorem , We can x x x Decompose to get x = p 1 k 1 p 2 k 2 … p n k n x=p_{1}^{k_{1}}p_{2}^{k_{2}}…p_{n}^{k_{n}} x=p1k1p2k2…pnkn.
Then there are f ( x ) = f ( p 1 k 1 ) f ( p 2 k 2 ) … f ( p n k n ) f(x)=f(p_{1}^{k_{1}})f(p_{2}^{k_{2}})…f(p_{n}^{k_{n}}) f(x)=f(p1k1)f(p2k2)…f(pnkn).
in other words , When we want to define an integral function , We just need to define the power of prime numbers , Then the function values of all numbers have been obtained .
Now? , We can pinch out a useless integral function by ourselves .
We define f ( x ) = { 1 , x = 1 p × k , x = p k , p yes quality Count , k yes just whole Count f(x)=\begin{cases} 1 & \text{,}x=1 \\ p\times k & \text{,}x=p^{k},p Prime number ,k It's a positive integer. \end{cases} f(x)={
1p×k,x=1,x=pk,p yes quality Count ,k yes just whole Count
Then explain when a ⊥ b a\perp b a⊥b when , f ( a b ) = f ( a ) f ( b ) f(ab)=f(a)f(b) f(ab)=f(a)f(b) that will do .( a ⊥ b a\perp b a⊥b Express a a a And b b b Coprime )
It's useless to pinch the product function .
Common product function :
Now let's talk about some useful integral functions .
Unit function and constant function :
Let's start with two obvious integrable functions .
The first is Unit function e ( n ) = [ n = 1 ] e(n)=[n=1] e(n)=[n=1],
( brackets [ ] [\;] [] Represents a logical operation , When the expression in parentheses holds , Then the value is 1 1 1, Instead of 0 0 0)
in other words , When x = 1 x=1 x=1 when , e ( x ) = 1 e(x)=1 e(x)=1; When x ≠ 1 x\neq 1 x=1 when , e ( x ) = 0 e(x)=0 e(x)=0.
It can be understood as unit element , There will be a deeper understanding later .
The second is Constant function 1 ( n ) = 1 1(n)=1 1(n)=1.
Cough , The first one here 1 1 1 Is a function symbol , Don't ask me why I said that .
The function is , For arbitrary x x x, All meet 1 ( x ) = 1 1(x)=1 1(x)=1.
Of course, these two functions are completely integrated functions , This is not the point , We continue .
Euler function φ ( n ) \varphi(n) φ(n):
Euler function φ ( n ) \varphi (n) φ(n), Less than or equal to n n n And with the n n n The number of Coprime numbers .
For example, less than or equal to 6 6 6, and 6 6 6 The number of Coprime is 1 1 1 and 5 5 5, therefore φ ( 6 ) = 2 \varphi(6)=2 φ(6)=2.
This function is more useful , I want to open a separate blog about , Here's just Prove that it is an integral function .
Because I can't prove , So here's a circular argument .
Let's just remember that it's an integral function , The hole left will be filled in when we talk about it .
One point , φ ( p k ) = p k − p k − 1 \varphi(p^{k})=p^{k}-p^{k-1} φ(pk)=pk−pk−1, among p p p Prime number , k k k It's a positive integer. .
The sum of factors and the number of factors :
Factors and functions σ ( n ) \sigma(n) σ(n), Express n n n The factor and , Yes σ ( n ) = ∑ d ∣ n d \sigma(n)=\sum_{d|n}d\; σ(n)=∑d∣nd.
Factor number function τ ( n ) \tau (n) τ(n), Express n n n The factor and , Yes τ ( n ) = ∑ d ∣ n 1 \tau (n)=\sum_{d|n}1\; τ(n)=∑d∣n1.
Prove that these two are integral functions , If you are interested, you can prove yourself .
here ∑ d ∣ n \sum_{d|n} ∑d∣n It's enumeration n n n All the factors of d d d.
It's also clear from the formula . The sum of factors is to enumerate all factors d d d, Then put all the factors d d d Add up . The number of factors is to enumerate all the factors , Then add one for each factor 1 1 1.
Give me the same ,
σ ( p k ) = 1 + p + p 2 + … + p k = p k + 1 − 1 p − 1 \sigma(p^{k})=1+p+p^{2}+…+p^{k}=\frac{p^{k+1}-1}{p-1} σ(pk)=1+p+p2+…+pk=p−1pk+1−1,
τ ( p k ) = k + 1 \tau(p^{k})=k+1 τ(pk)=k+1,
Both of them are easier to get out .
Mobius function μ ( n ) \mu(n) μ(n):
It's another function of the great God level , It's also a separate article , Let's start with the definition .
μ ( n ) = { 1 , x = 1 ( − 1 ) r , x = p 1 p 2 … p r , namely x Of the Yes plain because Son Time Count all by 1 , Its in r surface in plain because Son individual Count 0 , Its He love shape , namely x save stay flat Fang because Son \mu(n)=\begin{cases} 1 & \text{,}x=1 \\ (-1)^{r} & \text{,}x=p_{1}p_{2}…p_{r}, namely x The number of all prime factors is 1, among r Indicates the number of prime factors \\ 0 & \text{,} Other situations , namely x There is a square factor \end{cases} μ(n)=⎩⎪⎨⎪⎧1(−1)r0,x=1,x=p1p2…pr, namely x Of the Yes plain because Son Time Count all by 1, Its in r surface in plain because Son individual Count , Its He love shape , namely x save stay flat Fang because Son
This definition is outrageous , I'll talk about its origin later .
Now it's the same, as long as you know that it's an integral function .
Integral function sieve :
You need to know something , All integrable functions are OK o ( n ) o(n) o(n) Sifted out .
( Of course , When you just need to find the value of a function , Yes, there can be almost o ( n ) o(\sqrt{n}) o(n) The practice of getting faster , And screening is screening out 1 1 1 To n n n The value of the integral function of )
So how to screen ?
First , The integral function sieve is based on o ( n ) o(n) o(n) Based on the prime sieve .
Let's start with the linear prime sieve .
Linear prime sieve is improved on the basis of Egyptian sieve —— Let each number be sifted out by only one number .
We know , The Angstrom sieve uses every prime number , To sift its multiples . And the linear sieve , Make sure that each number is only screened out by its smallest prime factor .
Go straight to the code .
int notPrime[MAXN],prime[MAXN],tot;
void getPrime(int n)
{
notPrime[1]=1;
for(int i=2;i<=n;i++)
{
if(!notPrime[i])prime[tot++]=i;
for(int j=0;j<tot&&i*prime[j]<=n;j++)
{
notPrime[i*prime[j]]=1;
if(i%prime[j]==0)break;
}
}
}
Explain the principle of this code .
First , All composite numbers can be expressed as another number multiplied by its minimum prime factor .
So when we get a number , Just enumerate which prime number is selected as its minimum prime factor .
So this code , First, enumerate each number i i i, If not screened , Then throw it to the prime list p r i m e [ ] prime[] prime[] in .
Then for this number i i i, One more thing we have to do , Is to enumerate the smallest prime factor it multiplies p r i m e [ j ] prime[j] prime[j].
When i i i The number of , Can divide the current prime factor , Then you can't enumerate later . Because the current factor is i i i A prime factor of , If we enumerate later , It's bigger than this prime factor , Then it's not sifted by the smallest prime factor .
That's where the code ends .
Now let's talk about the sieve of integral functions .
In fact, it is an improvement on the basis of prime sieve .
First , For integrable functions f ( x ) f(x) f(x), We need to be able to quickly calculate f ( p k ) f(p^{k}) f(pk) The ability of , Just as we said in the previous definition , Then according to the properties of the integral function , Get other function values .
When it's done , We calculate the value of the integral function of each number at the position where it is screened out f ( x ) f(x) f(x).
First , When sifting out prime numbers , Let's just take the prime number p Function value of f ( p ) f(p) f(p) Fu Shang .
Then when you sift the numbers in the cycle , There are two situations , One is i i i Can not be p r i m e [ j ] prime[j] prime[j] Divisible , Then there is g c d ( i , p r i m e [ j ] ) = 1 gcd(i,prime[j])=1 gcd(i,prime[j])=1 establish , obtain f ( i × p r i m e [ j ] ) = f ( i ) f ( p r i m e [ j ] ) f(i\times prime[j])=f(i)f(prime[j]) f(i×prime[j])=f(i)f(prime[j]).
Then there is only one last case , Namely i i i Can be p r i m e [ j ] prime[j] prime[j] The condition of division , At this time, we deal with i i i The power of the smallest prime factor in l o w i low_{i} lowi, There is g c d ( i l o w i , p r i m e [ j ] × l o w i ) gcd(\frac{i}{low_{i}},prime[j]\times low_{i}) gcd(lowii,prime[j]×lowi), You can get f ( i × p r i m e [ j ] ) = f ( i l o w i ) f ( p r i m e [ j ] × l o w i ) f(i\times prime[j])=f(\frac{i}{low_{i}})f(prime[j]\times low_{i}) f(i×prime[j])=f(lowii)f(prime[j]×lowi).
Last , Find a way to deal with l o w i low_{i} lowi Just fine , This can also be handled during screening . Because we sift with the smallest prime factor , So there is l o w ( i × p r i m e [ j ] ) = l o w ( i ) × p r i m e [ j ] low(i\times prime[j])=low(i)\times prime[j] low(i×prime[j])=low(i)×prime[j].
Come here , And it's done .
Upper template .( This board is written now , There may be no problem )
int notPrime[MAXN],prime[MAXN],tot,low[MAXN];
int f[MAXN];
void getFunc(int n)
{
notPrime[1]=f[1]=low[1]=1;
for(int i=2;i<=n;i++)
{
if(!notPrime[i])low[i]=prime[tot++]=i,f[i]=( Prime numbers are calculated directly );
for(int j=0;j<tot&&i*prime[j]<=n;j++)
{
notPrime[i*prime[j]]=1;
if(i%prime[j])
{
low[i*prime[j]]=prime[j];
f[i*prime[j]]=f[i]*f[prime[j]];
}
else
{
low[i*prime[j]]=low[i]*prime[j];
if(low[i]==i)f[i*prime[j]]=( Direct calculation of prime power );
else f[i*prime[j]]=f[i/low[i]]*f[prime[j]*low[i]];
break;
}
}
}
}
The above is the general solution of integral function .
Now let's talk about special , Sieve method of Euler function and Mobius function .
The principle is the same , But there are some convenient places .
Let's start with Mobius function .
First, prime numbers p p p Function value of μ ( p ) = − 1 \mu(p)=-1 μ(p)=−1.
So when i i i Don't be p p p Divisible time , It's the same as seeking the law , Directly use the properties of integral function , μ ( i p ) = μ ( i ) μ ( p ) = − μ ( i ) \mu(ip)=\mu(i)\mu(p)=-\mu(i) μ(ip)=μ(i)μ(p)=−μ(i).
When i i i By p p p Divisible time ,( We know , When x x x When there is a square factor , μ ( x ) = 0 \mu(x)=0 μ(x)=0), You can boldly give 0 0 0 了 .
Templates :
int notPrime[MAXN],prime[MAXN],tot;
int mu[MAXN];
void initMu(int n)
{
notPrime[1]=mu[1]=1;
for(int i=2;i<=n;i++)
{
if(!notPrime[i])prime[tot++]=i,mu[i]=-1;
for(int j=0;j<tot&&i*prime[j]<=n;j++)
{
notPrime[i*prime[j]]=1;
if(i%prime[j])mu[i*prime[j]]=-mu[i];
else {
mu[i*prime[j]]=0;break;}
}
}
}
Then there's the Euler function ,
Prime time , φ ( p ) = p − 1 \varphi(p)=p-1 φ(p)=p−1.
Then it has a magical property , For a prime number p p p, if p ∣ i p|i p∣i, be φ ( i p ) = φ ( i ) p \varphi(ip)=\varphi(i)p φ(ip)=φ(i)p; if p p p Not divisible i i i, be φ ( i p ) = φ ( i ) ( p − 1 ) \varphi(ip)=\varphi(i)(p-1) φ(ip)=φ(i)(p−1).
And then according to this , It is also easy to write Euler functions .
int notPrime[MAXN],prime[MAXN],tot;
int phi[MAXN];
void initPhi(int n)
{
notPrime[1]=phi[1]=1;
for(int i=2;i<=n;i++)
{
if(!notPrime[i])prime[tot++]=i,phi[i]=i-1;
for(int j=0;j<tot&&i*prime[j]<=n;j++)
{
notPrime[i*prime[j]]=1;
if(i%prime[j])phi[i*prime[j]]=phi[i]*(prime[j]-1);
else {
phi[i*prime[j]]=phi[i]*prime[j];break;}
}
}
}
The product function sieve is finished .
Dirichlet :
Before we talk about it , Give a few more number theoretic functions .( Pay attention to the difference between number theoretic function and integral function )
i d ( n ) = n id(n)=n id(n)=n, Represents its own function , The function value is equal to the argument itself .
ω ( n ) = ∑ p ∣ n 1 \omega(n)=\sum_{p|n}1 ω(n)=∑p∣n1, among p p p Prime number , The function value represents n n n The number of prime factors of .
Let's talk. Let's talk .
Dirichlet convolution operation is an important algorithm of number theory function .
Yes , It's an algorithm , Like addition, subtraction, multiplication and division .
And it's the algorithm of the function , The result of the operation is also a function .
You can think of it this way , This is an operation mechanism specially established for number theory functions .
We will number theoretic functions f f f And number theoretic functions g g g, After Dirichlet convolution , Get a new number theoretic function h = f ∗ g h=f*g h=f∗g.( there ∗ * ∗ Not a multiplication sign , It's the sign of convolution )
So what's the algorithm .
That's the definition of convolution h ( n ) = ( f ∗ g ) ( n ) = ∑ d ∣ n f ( d ) g ( n d ) = ∑ d ∣ n f ( n d ) g ( d ) h(n)=(f*g)(n)=\sum_{d|n}f(d)g(\frac{n}{d})=\sum_{d|n}f(\frac{n}{d})g(d) h(n)=(f∗g)(n)=∑d∣nf(d)g(dn)=∑d∣nf(dn)g(d).
Now let's look at this formula , ∑ d ∣ n \sum_{d|n} ∑d∣n It should be no stranger , Is enumerating factors .
Let's go back to the previous two formulas .
Number of factors τ ( n ) = ∑ d ∣ n 1 \tau (n)=\sum_{d|n}1\; τ(n)=∑d∣n1, We find that this function is actually obtained by convolution of two constant functions .
We get a formula τ = 1 ∗ 1 \tau=1*1 τ=1∗1.
So in the same way , Look at the factors and σ ( n ) = ∑ d ∣ n d \sigma(n)=\sum_{d|n}d σ(n)=∑d∣nd, And then there is σ = 1 ∗ i d \sigma=1*id σ=1∗id.
Come here , Convolution operation should be simple to understand .
Also know Some properties of Dirichlet convolution operation .
First , it Satisfying the commutative law , Associative law .
then , For any number theoretic function f f f, Yes f ∗ e = f f*e=f f∗e=f, That is, the unit function is a unit element .
also , if f f f It's a product function , And g g g It's a product function , be f ∗ g f*g f∗g It's also a product function .
Convolution is probably like this .
Now List the convolution relations between some functions .
τ = 1 ∗ 1 \tau=1*1 τ=1∗1
σ = 1 ∗ i d \sigma=1*id σ=1∗id
1 ∗ μ = e 1*\mu=e 1∗μ=e
φ ∗ 1 = i d \varphi*1=id φ∗1=id
φ = i d ∗ μ \varphi=id*\mu φ=id∗μ
The first two formulas have been mentioned earlier , I won't talk about it .
You will find that the third formula is a magical formula , The constant function on the Mobius function volume is actually a unit element , let me put it another way , μ \mu μ and 1 1 1 It's the opposite of each other .
In fact, this is a pit buried in front of us , On the deviant definition of Mobius function .
You can understand , It is used to construct the inverse of a constant function , In this way, Mobius inversion can be realized , The blog in the next chapter will talk about .
thus , You can also get some more formulas , for example τ ∗ μ = 1 \tau*\mu=1 τ∗μ=1, σ ∗ μ = i d \sigma*\mu=id σ∗μ=id wait , That is, multiply both sides of the equation by μ \mu μ And 1 1 1 Offset .
Let's look at the last two formulas , It's actually the same formula , According to the front 1 1 1 and μ \mu μ The inverse element relation of .
As for why φ = i d ∗ μ \varphi=id*\mu φ=id∗μ, This formula is very important , I'll talk about it later in Mobius inversion .
This lesson is too big 6000 word , Hard top , It's over .
版权声明
本文为[Zimba_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230621425496.html
边栏推荐
- How to obtain geographical location based on photos and how to prevent photos from leaking geographical location
- Where is int a = 1 stored
- Operation not allowed for a result set of type resultset TYPE_ FORWARD_ ONLY. Explain in detail
- 个人主页软件Fenrus
- npm ERR! network
- Chinese Remainder Theorem and extended Chinese remainder theorem that can be understood by Aunt Baojie
- Leetcode question bank 78 Subset (recursive C implementation)
- Set the maximum width of the body, but why does the background color of the body cover the whole page?
- Practice of Flink streaming batch integration in Xiaomi
- JS case to find the maximum value, reverse the array, bubble sort
猜你喜欢

Kettle实验

Redis 内存占满导致的 Setnx 命令执行失败

Number of islands

Installation of data cleaning ETL tool kettle
![Cloud computing competition -- basic part of 2020 competition [task 3]](/img/a2/36ff5eafd18534207e6ab01422ea59.png)
Cloud computing competition -- basic part of 2020 competition [task 3]

JS DOM event

Introduction to sap pi / PO login and basic functions

Redis exception read error on connection solution

MySQL of database -- overview and installation

Practice of Flink streaming batch integration in Xiaomi
随机推荐
Cross domain configuration error: when allowcredentials is true, allowedorigins cannot contain the special value "*“
Single sign on SSO
个人主页软件Fenrus
NPM reports an error: operation not allowed, MKDIR 'C: \ program files \ node JS \ node_ cache _ cacache’
Summary of common concepts and problems of linear algebra in postgraduate entrance examination
What is monitoring intelligent playback and how to use intelligent playback to query video recording
OpenCV中的图像处理 —— 轮廓入门+轮廓特征
ABAP CDs view with association example
Kettle experiment conversion case
Simple understanding of arguments in JS
Enter "net start MySQL" and "system error 5. Access denied" appears. Detailed explanation of the problem
Kettle experiment (III)
Redis expired key cleaning and deletion policy summary
Explanation of order and primitive root of number theory
Leetcode0587. Install fence
(Extended) bsgs and higher order congruence equation
Cloud computing competition -- basic part of 2020 competition [task 3]
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
npm ERR! network
SAP CR transmission request sequence and dependency check