Cod sursa(job #2104410)

Utilizator AlexandruGabrielAliciuc Alexandru AlexandruGabriel Data 11 ianuarie 2018 17:14:05
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("lgput.in");
ofstream fout ("lgput.out");

long long Exponentiere(long long x, long long n)
{
    long long p=1;
    while (n)
    {
        if (n%2==1)
        {
            p=p*x%1999999973;
            n--;
        }
        x=x*x%1999999973;
        n=n/2;
    }
    return p;
}

int main()
{
    long long x,n;
    fin>>x>>n;
    fout<<Exponentiere(x,n);
    return 0;
}