Cod sursa(job #1708811)
Utilizator | Data | 27 mai 2016 23:33:17 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <fstream>
#define XYZ 1999999973
using namespace std;
ifstream cin("lgput.in");
ofstream cout("lgput.out");
long long PutereLogaritmic(long long x, int n)
{
long long p=1 ;
while (n>0)
{
if (n%2==1)
{ p*=x;
n-- ;
}
x=x*x ;
n=n/2;
}
return p ;
}
long long N,P;
int main()
{
cin>>N>>P;
cout<<PutereLogaritmic(N,P)%XYZ;
cin.close();
cout.close();
return 0;
}