Cod sursa(job #477195)
Utilizator | Claudiu Mihail claudiumihail | Data | 13 august 2010 19:31:49 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include<fstream>
#include<iostream>
using namespace std;
unsigned long long X=1999999973;
unsigned long Exp(unsigned long long N,unsigned long P)
{
if(P==0)
return 1;
else if(P==1)
return N;
else
{
if(P%2)
return (Exp(N,P>>1)*Exp(N,P>>1)*N)%X;
else
return (Exp(N,P>>1)*Exp(N,P>>1))%X;
}
}
int main()
{
unsigned int N,P;
fstream fin("lgput.in",fstream::in);
fstream fout("lgput.out",fstream::out);
fin>>N>>P;
fin.close();
fout<<Exp(N,P)%X<<endl;
fout.close();
return 0;
}