Kyopro Library
読み取り中…
検索中…
一致する文字列を見つけられません
zeta_mobius_div_mul.hpp
[詳解]
1
#
include
"../../kyopro_library/template.hpp"
2
#
include
"../../kyopro_library/math/prime_enumerate.hpp"
3
4
/// @brief 倍数・約数ゼータ・メビウス変換
5
namespace
ZetaMobiusDivMul
{
6
vector
<
int
>
primes
;
7
void
Init
(
int
n=1e6) { primes=PrimeEnumerate(n); }
8
9
/// @brief 倍数高速ゼータ変換
10
/// @brief v'[k] = Σ_{k|d} v[d] なる v' を返す
11
/// @note O(N log(log(N)))
12
template
<
typename
Monoid>
13
vector
<
typename
Monoid
::
Type
>
MultipleZeta
(vector<
typename
Monoid::Type> v) {
14
int
n=v.size()-1;
15
if
((
int
)primes.size()<n)
Init
(
n
)
;
16
for
(
int
p: primes)
for
(
int
k=n/p; k>0; k--) v[k]=Monoid::op(v[k],v[k*p]);
17
return
v;
18
}
19
20
/// @brief 約数高速ゼータ変換
21
/// @brief v'[k] = Σ_{d|k} v[d] なる v' を返す
22
/// @note O(N log(log(N)))
23
template
<
typename
Monoid>
24
vector
<
typename
Monoid
::
Type
>
DvisorZeta
(vector<
typename
Monoid::Type> v) {
25
int
n=v.size()-1;
26
if
((
int
)primes.size()<n)
Init
(
n
)
;
27
for
(
int
p: primes)
for
(
int
k=1; k*p<=n; k++) v[k*p]=Monoid::op(v[k*p],v[k]);
28
return
v;
29
}
30
31
/// @brief 倍数高速メビウス変換
32
/// @brief v'[k] = Σ_{k|d} μ(d) v[d] なる v' を返す
33
/// @note 逆変換が必要なので、v は可換群の元である必要がある
34
/// @note O(N log(log(N)))
35
template
<
typename
Abel>
36
vector
<
typename
Abel
::
Type
>
MultipleMobius
(vector<
typename
Abel::Type> v) {
37
int
n=v.size()-1;
38
if
((
int
)primes.size()<n)
Init
(
n
)
;
39
for
(
int
p: primes)
for
(
int
k=1; k*p<=n; k++) v[k]=Abel::op(v[k],Abel::inv(v[k*p]));
40
return
v;
41
}
42
43
/// @brief 約数高速メビウス変換
44
/// @brief v'[k] = Σ_{d|k} μ(d) v[k/d] なる v' を返す
45
/// @note 逆変換が必要なので、v は可換群の元である必要がある
46
/// @note O(N log(log(N)))
47
template
<
typename
Abel>
48
vector
<
typename
Abel
::
Type
>
DivisorMobius
(vector<
typename
Abel::Type> v) {
49
int
n=v.size()-1;
50
if
((
int
)primes.size()<n)
Init
(
n
)
;
51
for
(
int
p: primes)
for
(
int
k=n/p; k>0; k--) v[k*p]=Abel::op(v[k*p],Abel::inv(v[k]));
52
return
v;
53
}
54
};
55
56
#
include
"../../kyopro_library/others/monoid.hpp"
57
#
include
"../../kyopro_library/others/abel.hpp"
ZetaMobiusDivMul
倍数・約数ゼータ・メビウス変換
Definition
zeta_mobius_div_mul.hpp:5
ZetaMobiusDivMul::MultipleMobius
vector< typename Abel::Type > MultipleMobius(vector< typename Abel::Type > v)
倍数高速メビウス変換
Definition
zeta_mobius_div_mul.hpp:36
ZetaMobiusDivMul::MultipleZeta
vector< typename Monoid::Type > MultipleZeta(vector< typename Monoid::Type > v)
倍数高速ゼータ変換
Definition
zeta_mobius_div_mul.hpp:13
ZetaMobiusDivMul::DvisorZeta
vector< typename Monoid::Type > DvisorZeta(vector< typename Monoid::Type > v)
約数高速ゼータ変換
Definition
zeta_mobius_div_mul.hpp:24
ZetaMobiusDivMul::primes
vector< int > primes
Definition
zeta_mobius_div_mul.hpp:6
ZetaMobiusDivMul::Init
void Init(int n=1e6)
Definition
zeta_mobius_div_mul.hpp:7
ZetaMobiusDivMul::DivisorMobius
vector< typename Abel::Type > DivisorMobius(vector< typename Abel::Type > v)
約数高速メビウス変換
Definition
zeta_mobius_div_mul.hpp:48
algorithm
zeta_mobius_div_mul.hpp
構築:
1.13.2