Kyopro Library
読み取り中…
検索中…
一致する文字列を見つけられません
totient.hpp
[詳解]
1
#
include
"../../kyopro_library/template.hpp"
2
3
/// @brief オイラーのtotient関数
4
/// @brief n 以下で n と互いに素な自然数の個数を返す。
5
/// @note O(sqrt(N))
6
ll
Totient
(ll n) {
7
// totient(n) = n * (1-1/p1) * (1-1/p2) * ... * (1-1/pk) (p1,p2,...,pk は n の素因数)
8
ll ret=n;
9
for
(ll i=2; i*i<=n; i++)
if
(n%i==0) {
10
ret-=ret/i;
11
while
(n%i==0) n/=i;
12
}
13
if
(n>1) ret-=ret/n;
14
return
ret;
15
}
Totient
ll Totient(ll n)
オイラーのtotient関数
Definition
totient.hpp:6
math
totient.hpp
構築:
1.13.2