Cod sursa(job #2043683)

Utilizator gundorfMoldovan George gundorf Data 20 octombrie 2017 12:53:06
Problema Ridicare la putere in timp logaritmic Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int  c=1999999973;

long long  exp_lg (long long x ,long long p)
{
    long long z;
    if (p==1) return x%c;
    if (p==0) return 1;
    if (p==2) return (x*x)%c;
    z=exp_lg(x,p/2);
    if (p%2==0) return (1LL*z*z)%c;
    else return (1LL*z*z*x)%c;

}
int main()
{
long long x,p;

    fin>>x>>p;
    //fout<<x<<" "<<p;
    fout<<exp_lg(x,p);

    return 0;
}