Cod sursa(job #1707026)
Utilizator | Data | 24 mai 2016 00:21:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
#define XYZ 1999999973
using namespace std;
ifstream cin("lgput.in");
ofstream cout("lgput.out");
long long n,p;
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 ;
}
int main()
{
cin>>n>>p;
long long rez;
rez=PutereLogaritmic(n,p);
cout<<rez%XYZ;
cin.close();
cout.close();
return 0;
}