Cod sursa(job #2045808)

Utilizator costi2Radu Canu costi2 Data 22 octombrie 2017 21:19:53
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <fstream>
#include <iostream>

using namespace std;

ifstream in("lgput.in");
ofstream out("lgput.out");
#define MAX 1999999973
long power(long x,long power)
{
        long res = 1;
        while(power > 0)
        {
                if(power & 1)
                        res = (res*x)%MAX;
                power = power >> 1;
                x = (x*x) % MAX;
        }
        return res;
}
int main()
{
        long a,b;
        in >> a >> b;
        out << power(a,b);
        return 0;
}