Cod sursa(job #283625)

Utilizator victorsbVictor Rusu victorsb Data 19 martie 2009 14:19:11
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define FIN "lgput.in"
#define FOUT "lgput.out"

typedef long long LL;

const LL MOD = 1999999973;

LL N, P;

void read() {
    scanf("%lld %lld", &N, &P);
}

LL pow(int N, int P) {
    if (P == 0)
        return 1;
    if (P == 1)
        return N % MOD;
    if (P % 2)
        return (N * pow(N, P - 1)) % MOD;
    else {
        LL tmp = pow(N, P / 2);
        return (tmp * tmp) % MOD;
    }
}

void solve() {
    printf("%lld\n", pow(N, P));
}

int main() {
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
    read();
    solve();
    return 0;
}