Cod sursa(job #1975498)

Utilizator MaligMamaliga cu smantana Malig Data 1 mai 2017 09:26:35
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>

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

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

ll N,K;

ll pw(ll,ll);

int main() {
    in>>N>>K;
    out<<pw(N,K)<<'\n';

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

ll pw(ll base,ll exp) {
    if (!exp) {
        return 1;
    }
    if (exp == 1) {
        return base % mod;
    }
    if (exp & 1) {
        return (base * pw(base * base,(exp-1)>>1) ) % mod;
    }
    return pw(base * base, (exp)>>1) % mod;
}