Cod sursa(job #2586236)

Utilizator sulzandreiandrei sulzandrei Data 20 martie 2020 01:44:58
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <utility>


using namespace std;

ifstream in("lgput.in");
ofstream out("lgput.out");
#define ull long long int

#define MOD 1999999973

ull logExp( ull x, ull n)
{
    if(n==1)
        return x;
    return (n%2)
           ? x*logExp(x*x%MOD, (n-1)/2)%MOD
           : logExp((x*x)%MOD, n/2)%MOD;
}


ull mod(ull a, ull b)
{
    return a*b%MOD;
}

ull binExp(ull x, ull n)
{
    n >>=1;
    ull res = 1;
    ull power = x;
    while(n)
    {
        if (n&1)
        {
            res = mod(res,power);
        }
        power = mod(power,power);
        n >>=1;

    }


}

int main ( )
{
    ull n,p;
    in>>n>>p;
    out<<binExp(n,p);


    return 0;
}