This documentation is automatically generated by online-judge-tools/verification-helper
#include "Mathematics/mod_pow_inv.hpp"
整数 $a, x, m$ に対して $a^x \pmod{m}$ や $a^{-1} \pmod{m}$ を求めます。
整数 $x, n, m$ に対して $x^n \pmod{m}$ を返します。
制約
T
は int
, unsigned int
, long long
, unsigned long long
T
で表現可能計算量
整数 $x, m$ に対して $x^{-1} \pmod{m}$ を返します。
制約
T
は int
, long long
計算量
#include <bits/stdc++.h>
#include "Mathematics/mod_pow_inv.hpp"
using namespace std;
int main() {
cout << "mod_pow(2, 3, 3) = " << tk::mod_pow(2, 3, 3) << endl; // 2 (2^3 = 8)
cout << "mod_pow(5, 0, 10) = " << tk::mod_pow(2, 3, 3) << endl; // 1 (5^0 = 1)
cout << "mod_pow(10, 2, 10000) = " << tk::mod_pow(10, 2, 10000) << endl; // 100 (10^2 = 100)
cout << "mod_inv(10, 7) = " << tk::mod_inv(10, 7) << endl; // -2 (10*(-2) = -20 = 7*(-3) + 1)
cout << "mod_inv(4, 3) = " << tk::mod_inv(4, 3) << endl; // 1 (4*1 = 3*1 + 1)
cout << "mod_inv(-5, 8) = " << tk::mod_inv(-5, 8) << endl; // 3 (-5*3 = 8*(-2) + 1)
}
2020/01/14: https://noshi91.hatenablog.com/entry/2019/04/01/184957