Cod sursa(job #2449277)

Utilizator Dragos1226Dragos Chileban Dragos1226 Data 19 august 2019 04:14:48
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include<bits/stdc++.h>

using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
const int MOD = 1999999973;

int pow_log (int n, int p) {
    int r = 1;
    while(p) {
        if (p % 2 == 1)
            r = (1LL * r * n) % MOD;
            n = (1LL * n * n) % MOD;
            p = p / 2;
    }
    return r;
}

int main() {
   int n, p;
   in >> n >> p;
   out << pow_log(n,p);
}