rcpl

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ruthen71/rcpl

:heavy_check_mark: verify/aoj_ntl/aoj_ntl_1_b.test.cpp

Depends on

Code

#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_B"

#include <bits/stdc++.h>

#include "math/pow_mod.hpp"

int main() {
    // a = 0
    assert(pow_mod(0, 0, 1) == 0);  // 0 ^ 0 = 1
    assert(pow_mod(0, 0, 2) == 1);
    assert(pow_mod(0, 0, 3) == 1);
    assert(pow_mod(0, 1, 1) == 0);  // 0 ^ 1 = 0
    assert(pow_mod(0, 1, 2) == 0);
    assert(pow_mod(0, 1, 3) == 0);
    assert(pow_mod(0, 2, 1) == 0);  // 0 ^ 2 = 0
    assert(pow_mod(0, 2, 2) == 0);
    assert(pow_mod(0, 2, 3) == 0);
    // a > 0, n = 0
    assert(pow_mod(1, 0, 1) == 0);  // 1 ^ 0 = 1
    assert(pow_mod(1, 0, 2) == 1);
    assert(pow_mod(1, 0, 3) == 1);
    assert(pow_mod(2, 0, 1) == 0);  // 2 ^ 0 = 1
    assert(pow_mod(2, 0, 2) == 1);
    assert(pow_mod(2, 0, 3) == 1);
    long long m, n;
    std::cin >> m >> n;
    std::cout << pow_mod(m, n, 1000000007) << '\n';
    return 0;
}
#line 1 "verify/aoj_ntl/aoj_ntl_1_b.test.cpp"
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_B"

#include <bits/stdc++.h>

#line 2 "math/pow_mod.hpp"

long long pow_mod(long long a, long long n, const long long mod) {
    assert(n >= 0 and mod >= 1);
    if (mod == 1) return 0;
    a %= mod;
    if (a < 0) a += mod;
    long long res = 1;
    while (n) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
#line 6 "verify/aoj_ntl/aoj_ntl_1_b.test.cpp"

int main() {
    // a = 0
    assert(pow_mod(0, 0, 1) == 0);  // 0 ^ 0 = 1
    assert(pow_mod(0, 0, 2) == 1);
    assert(pow_mod(0, 0, 3) == 1);
    assert(pow_mod(0, 1, 1) == 0);  // 0 ^ 1 = 0
    assert(pow_mod(0, 1, 2) == 0);
    assert(pow_mod(0, 1, 3) == 0);
    assert(pow_mod(0, 2, 1) == 0);  // 0 ^ 2 = 0
    assert(pow_mod(0, 2, 2) == 0);
    assert(pow_mod(0, 2, 3) == 0);
    // a > 0, n = 0
    assert(pow_mod(1, 0, 1) == 0);  // 1 ^ 0 = 1
    assert(pow_mod(1, 0, 2) == 1);
    assert(pow_mod(1, 0, 3) == 1);
    assert(pow_mod(2, 0, 1) == 0);  // 2 ^ 0 = 1
    assert(pow_mod(2, 0, 2) == 1);
    assert(pow_mod(2, 0, 3) == 1);
    long long m, n;
    std::cin >> m >> n;
    std::cout << pow_mod(m, n, 1000000007) << '\n';
    return 0;
}
Back to top page