maomao90's Library
A C++20 library for competitive programming.
Loading...
Searching...
No Matches
pow_mod.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <concepts>
4
5
#include "
library/internal/concepts.hpp
"
6
#include "
library/internal/type_traits.hpp
"
7
8
namespace
maomao90
{
9
using namespace
std;
10
template
<
int
egral T,
int
ernal::concepts::broadly_
unsigned
_
int
egral P>
11
requires
internal::type_traits::is_64bit_or_less_v<T>
12
constexpr
T
pow_mod
(T b, P p, T mod) {
13
using
U = internal::type_traits::safely_multipliable_t<T>;
14
T res = 1;
15
b %= mod;
16
if
(b < 0) {
17
b += mod;
18
}
19
while
(p) {
20
if
(p & 1) {
21
res = (U)res * b % mod;
22
}
23
b = (U)b * b % mod;
24
p >>= 1;
25
}
26
return
res;
27
}
28
}
// namespace maomao90
concepts.hpp
maomao90
Definition
hashmap.hpp:8
maomao90::pow_mod
constexpr T pow_mod(T b, P p, T mod)
Definition
pow_mod.hpp:12
type_traits.hpp
library
math
pow_mod.hpp
Generated by
1.13.2