Skip to content

Commit 7567e13

Browse files
committed
add constexpr to modint functions
1 parent 5f8b24e commit 7567e13

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cp-algo/number_theory/modint.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ namespace cp_algo::math {
1212
static constexpr size_t bits = sizeof(Int) * 8;
1313
using Int2 = std::conditional_t<bits <= 32, int64_t, __int128_t>;
1414
using UInt2 = std::conditional_t<bits <= 32, uint64_t, __uint128_t>;
15-
static Int mod() {
15+
constexpr static Int mod() {
1616
return modint::mod();
1717
}
18-
static Int remod() {
18+
constexpr static Int remod() {
1919
return modint::remod();
2020
}
21-
static UInt2 modmod() {
21+
constexpr static UInt2 modmod() {
2222
return UInt2(mod()) * mod();
2323
}
24-
modint_base() = default;
25-
modint_base(Int2 rr) {
24+
constexpr modint_base() = default;
25+
constexpr modint_base(Int2 rr) {
2626
to_modint().setr(UInt((rr + modmod()) % mod()));
2727
}
2828
modint inv() const {
@@ -63,10 +63,10 @@ namespace cp_algo::math {
6363
UInt R = to_modint().getr();
6464
return R - (R > (UInt)mod() / 2) * mod();
6565
}
66-
void setr(UInt rr) {
66+
constexpr void setr(UInt rr) {
6767
r = rr;
6868
}
69-
UInt getr() const {
69+
constexpr UInt getr() const {
7070
return r;
7171
}
7272

@@ -85,8 +85,8 @@ namespace cp_algo::math {
8585
protected:
8686
UInt r;
8787
private:
88-
modint& to_modint() {return static_cast<modint&>(*this);}
89-
modint const& to_modint() const {return static_cast<modint const&>(*this);}
88+
constexpr modint& to_modint() {return static_cast<modint&>(*this);}
89+
constexpr modint const& to_modint() const {return static_cast<modint const&>(*this);}
9090
};
9191
template<typename modint>
9292
concept modint_type = std::is_base_of_v<modint_base<modint, typename modint::Int>, modint>;

0 commit comments

Comments
 (0)