Cod sursa(job #2762907)

Utilizator Teodor_AxinteAxinte Teodor-Ionut Teodor_Axinte Data 9 iulie 2021 21:11:16
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>

using namespace std;

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

const long long int MOD = 1999999973;

long long int power(int b, int e) {
    if (e == 0)
        return 1;
    long long int r=power(b,e/2)%MOD;
    r=(r%MOD*r%MOD)%MOD;
    if(e%2==1)
        r=(r*b)%MOD;
    return r%MOD;
}

long long int a, b;

int main() {
    fin >> a >> b;
    a%=MOD;b%=MOD;
    fout << power(a, b) % MOD;
    return 0;
}