Cod sursa(job #1987265)

Utilizator MaligMamaliga cu smantana Malig Data 30 mai 2017 08:06:55
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>

using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");

#define ll long long
#define pb push_back
const int NMax = 1e5 + 5;
const ll inf = 9e18 + 5;
const int mod = 1999999973;

ll A,B;

ll pw(ll,ll);

int main() {
    in>>A>>B;
    out<<pw(A,B);

    in.close();out.close();
    return 0;
}

ll pw(ll base,ll exp) {
    if (exp == 0) {
        return 1;
    }
    if (exp == 1) {
        return base;
    }
    if (exp & 1) {
        return base * pw(base*base % mod,(exp-1)/2) % mod;
    }
    return pw(base*base % mod,exp/2) % mod;

}