Cod sursa(job #2238886)

Utilizator cristinaandrei10Andrei Cristina cristinaandrei10 Data 8 septembrie 2018 11:28:05
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <fstream>

using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
typedef long long LL;
const LL MOD = 1999999973;
LL expo(LL baza ,LL exponent)
{
    if(exponent == 0)
        return 1;
    LL radical = expo(baza ,exponent / 2);
    LL putere = radical * radical % MOD;
    if(exponent % 2 == 1)
        putere = putere * baza % MOD;
    return putere;

}
LL N,P;
int main()
{
    f>>N>>P;
    g<<expo(N,P);
    return 0;
}