Cod sursa(job #2618697)

Utilizator mex7Alexandru Valentin mex7 Data 25 mai 2020 19:45:17
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ifstream fin("lgput.in");
ofstream fout("lgput.out");
ll mod = 1999999973;

ll power(ll base, ll pw) {
    if (pw == 1)
        return base;
    if (pw == 0)
        return pw;

    if (pw % 2)
        return base * power(base % mod * base % mod, pw / 2) % mod;
    return power(base % mod * base % mod, pw / 2) % mod;
}


int main() {
    ll k, n;

    cin >> n >> k;

    cout << power(n, k);

    return 0;
}