Cod sursa(job #1918711)

Utilizator tudormaximTudor Maxim tudormaxim Data 9 martie 2017 16:37:14
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <iostream>
#include <fstream>
using namespace std;
typedef long long LL;

ifstream fin ("lgput.in");
ofstream fout ("lgput.out");

const int mod = 1999999973;

LL Log_pow (LL n, LL p) {
    LL ans = 1;
    while (p) {
        if (p & 1) ans = (ans * n) % mod;
        n = (n * n) % mod;
        p = p >> 1;
    }
    return ans;
}

int main() {
    LL n, p;
    fin >> n >> p;
    fout << Log_pow(n, p) << '\n';
    fin.close();
    fout.close();
    return 0;
}