Cod sursa(job #2371441)

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

#define ll long long

using namespace std;
int m = 1999999973;
ll pow(ll base, ll exp) {
    ll sol = 1;
    for (; exp; exp >>= 1, base = (base * base) % m) {
        if (exp & 1)
            sol = (sol * base) % m;
    }
    return sol;
}

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

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