generated from Enriquefft/cpp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
177f078
commit d4541a3
Showing
2 changed files
with
32 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <cstdint> | ||
using ll = intmax_t; | ||
using ull = uintmax_t; | ||
|
||
constexpr ll MODULO = 1000000007; | ||
|
||
// exponent is very large | ||
// modulo is prime (1e9 + 7) | ||
// base is always 2 | ||
|
||
/// @brief Binary Exponentiation with modulo | ||
/// @param expo exponent | ||
/// @param base base (default: 2) | ||
/// @param modulo modulo | ||
template <bool USE_FERMAT_LITTLE_THEOREM = false> | ||
constexpr auto bin_mod_exp(ll expo, ll base = 2, ll modulo = MODULO) -> ll { | ||
|
||
if constexpr (USE_FERMAT_LITTLE_THEOREM) { | ||
expo %= (modulo - 1); | ||
} | ||
|
||
ll res = 1; | ||
|
||
while (expo > 0) { | ||
if (expo & 1LL) { | ||
res = (res * base) % modulo; | ||
} | ||
base = (base * base) % modulo; | ||
expo >>= 1LL; | ||
} | ||
return res; | ||
} |
This file was deleted.
Oops, something went wrong.