尤拉函式的學習

2021-09-27 07:57:39 字數 1282 閱讀 5972

尤拉函式的定義

1 ~ n 中與 n 互質的數的個數被稱為尤拉函式,記為ϕ(n)。

若在算數基本定理中,n = p1 ^ a1 * p2 ^ a2 * … * pk ^ ak

那麼ϕ(n) = n * (1 - 1 / p1) * (1 - 1 / p2) * … * (1 - 1 / pk).

證明過程:

所用到的原理:容斥原理

1.從1 - n 中去掉 p1, p2, …, pk的所有的倍數

2. 加上所有 pi * pj 的倍數

…所以有:

ϕ(n) = n - n / p1 - n / p2 - n / p3 - … - n / pk + n / p1 * p2 + n / p1 * p3 + … n / pk * p(k - 1) - n / p1 * p2 * p3 …

所有得到:ϕ(n) = n * (1 - 1 / p1) * (1 - 1/ p2) * … * (1 - 1 / pk).

#include #include using namespace std;

int main(void)

}if(x > 1) res = res / x * (x - 1);

printf("%d\n", res);

}return 0;

}

#include #include using namespace std;

const int maxn = 1e6 + 5;

bool vis[maxn];

int prime[maxn], phi[maxn], cnt;

inline void get_phi(int n) else phi[i * prime[j]] = phi[i] * (prime[j] - 1);}}

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

res += phi[i];

printf("%lld\n", res);

}int main(void)

證明:

當 i 是質數的時候,phi[i] = i - 1;

當 i 是和數的時候:

1.當 i % prime[j] == 0 時:phi[i * prime[j]] = phi[i] * prime[j]

2.當 i % prime[j] != 0 時, phi[i * prime[j]] = phi[i] * primep[j] * (1 - 1 / prime[j])

= phi[i] * (prime[j] - 1)

尤拉函式 尤拉定理

尤拉函式 對正整數 n,尤拉函式 是小於等於 n的數中與 n互質的數的數目 此函式以其首名研究者尤拉命名 euler so totientfunction 它又稱為 euler stotient function 函式 尤拉商數等。例如 8 4,因為 1,3,5,7均和8 互質。注 n為1時尤拉函式...

尤拉函式 尤拉定理

尤拉函式 設 n 為正整數,則 1,2,n 中與 n 互素的整數的個數計作 n 叫做尤拉函式。設 p 是素數,p p 1設 p 是素數,pa pa p a 1 設 p,q 是不同的素數,n q p,n p q 即 n p 1 q 1 設 m,n 是兩個正整數,且 m,n 1,若 n m n,n m ...

尤拉函式尤拉篩

尤拉函式求小於等於n與n互質的數的個數 複習時發現這個知識點竟然沒有整理 n為素數即為n 1 除了其本身 n為素數的倍數 ola sushu j i ola i sushu j else ola sushu j i ola i sushu j 1 include include include in...