Cod sursa(job #2173979)

Utilizator george.ursachiUrsachi George george.ursachi Data 16 martie 2018 10:08:06
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>

using namespace std;

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

const long MOD=1999999973;
typedef unsigned long long ull;
ull N,P;

ull lgput(ull a, ull b)
{
    if(b==0) return 1;
    if(b==1) return a;
    ull aux=lgput(a, b/2);
    if(b&1) return ((((aux*aux)%MOD)*a)%MOD);
    return (aux*aux)%MOD;

}

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