Cod sursa(job #2159645)

Utilizator Daniel_ApopeiDaniel Apopei Daniel_Apopei Data 11 martie 2018 07:37:04
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include<iostream>
#include<fstream>
#define ull unsigned long long
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
ull a,b;
const ull MOD = 1999999973;
ull powr(ull x,ull y)
{
    ull p=1;
    while(y)
    {
        while(y%2==0)
        {
            y/=2;
            x=x*x;
        }
        p*=x;
        p=p%MOD;
        y--;
    }
    return p%MOD;
}
int main()
{
    f>>a>>b;
    g<<powr(a,b);
    return 0;
}