Cod sursa(job #3205260)

Utilizator BledeaAlexBledea Alexandru BledeaAlex Data 19 februarie 2024 09:50:19
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <iostream>
#include <fstream>

typedef long long LL;

using namespace std;

ifstream f("lgput.in");
ofstream g("lgput.out");

const int MOD = 1999999973;

LL n, p;

LL pow(LL n, LL p){
    LL rez = 1, f = n;

    while(p){
        if(p % 2 == 1)
            rez = (rez * f) % MOD;
        f = (f * f) % MOD;
        p >>= 1;
    }

    return rez;
}

int main()
{
    f >> n >> p;

    g << pow(n, p);

    return 0;
}