This documentation is automatically generated by competitive-verifier/competitive-verifier
#include "math/combinatorics/mod-pow.hpp"ある値のべき乗を求める。
T mod_pow(T x, int64_t n, const T& p)
$x^n \bmod p$ を返す。
#pragma once
#include <cstdint>
/**
* @brief Mod Pow(べき乗)
*
*/
template <typename T>
T mod_pow(T x, std::int64_t n, const T& p) {
T ret = 1;
while (n > 0) {
if (n & 1) (ret *= x) %= p;
(x *= x) %= p;
n >>= 1;
}
return ret % p;
}
#line 2 "math/combinatorics/mod-pow.hpp"
#include <cstdint>
/**
* @brief Mod Pow(べき乗)
*
*/
template <typename T>
T mod_pow(T x, std::int64_t n, const T& p) {
T ret = 1;
while (n > 0) {
if (n & 1) (ret *= x) %= p;
(x *= x) %= p;
n >>= 1;
}
return ret % p;
}