Kyopro Library
読み取り中…
検索中…
一致する文字列を見つけられません
totient_table.hpp
[詳解]
1
#
include
"../../kyopro_library/template.hpp"
2
3
/// @brief オイラーのtotient関数を前計算する
4
/// @brief totient(0) ... totient(n) を前計算する
5
/// @note O(n log(log(n)))
6
/// @ref https://qiita.com/drken/items/3beb679e54266f20ab63
7
/// @ref https://manabitimes.jp/math/667
8
/// @brief totient(i) = i 以下であって、i と互いに素な数の個数
9
/// @brief 公式: totient(n) = n * Π(1 - 1/p) (p は n の素因数)
10
/// @brief 公式: totient(n)totient(m) = totient(nm) (n と m が互いに素)
11
/// @brief 公式: Σ(d | n) totient(d) = n
12
/// @brief 公式: a^totient(m) ≡ 1 (mod m) (a と m が互いに素)
13
vector
<
ll
>
TotientTable
(ll n) {
14
vector<ll> ret(n+1);
15
iota(ret.begin(),ret.end(),0);
16
17
for
(ll i=2; i<=n; i++)
if
(ret[i]==i)
for
(ll j=i; j<=n; j+=i) ret[j]=ret[j]/i*(i-1);
18
19
return
ret;
20
}
TotientTable
vector< ll > TotientTable(ll n)
オイラーのtotient関数を前計算する
Definition
totient_table.hpp:13
math
totient_table.hpp
構築:
1.13.2