Cod sursa(job #2371275)

Utilizator TyFrostbyteIon Robert-Gabriel TyFrostbyte Data 6 martie 2019 17:00:58
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <iostream>
#include <cstdio>

#define ll long long

using namespace std;

ll pow(ll base, ll exp){
    if(exp == 1)
        return base%1999999973;
    if(exp%2==0)
        return pow(base*base, exp/2)%1999999973;
    return base*pow(base*base, exp/2)%1999999973;
}

int main() {
    freopen("lgput.in", "r", stdin);
    freopen("lgput.out", "w", stdout);

    ll a, b;
    cin >> a >> b;
    cout << pow(a, b);
    return 0;
}