Kyopro Library
読み取り中…
検索中…
一致する文字列を見つけられません
modlog.hpp
[詳解]
1
#
include
"../../kyopro_library/template.hpp"
2
3
/// @brief 離散対数問題
4
/// @brief x^k=y mod m なる最小の k を返す
5
/// @note O(sqrt(m))
6
/// @attention p は素数
7
ll
ModLog
(ll x, ll y, ll mod) {
8
ll m=ceil(sqrt(mod))+1;
9
ll now_y=y;
10
map<ll,ll> mp;
11
for
(
int
i=0; i<m; i++) {
12
mp[now_y]=i;
13
now_y=now_y*x%mod;
14
}
15
ll x_pow=1;
16
for
(
int
i=0; i<m; i++) {
17
x_pow*=x;
18
x_pow%=mod;
19
}
20
ll now_x=x_pow;
21
for
(
int
i=1; i<=m; i++) {
22
if
(mp.find(now_x)!=mp.end())
return
i*m-mp[now_x];
23
now_x=now_x*x_pow%mod;
24
}
25
return
-1;
26
}
ModLog
ll ModLog(ll x, ll y, ll mod)
離散対数問題
Definition
modlog.hpp:7
math
modlog.hpp
構築:
1.13.2