Cod sursa(job #2043616)

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

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

}
int main()
{
    int x,p;
    fin>>x>>p;
    fout<<exp_lg(x,p);
    return 0;
}