Cod sursa(job #1162987)
Utilizator | Data | 1 aprilie 2014 09:00:24 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include<fstream>
#include<algorithm>
using namespace std;
ifstream cin("lgput.in");
ofstream cout("lgput.out");
long long n,p;
long long exp(long long n,long long p){
if(p==0){
return 1;
}else{
if(p==1){
return n%1999999973;
}else{
if(p%2){
return n*exp(n*n,p/2)%1999999973;
}else{
return exp(n*n,p/2)%1999999973;
}
}
}
}
int main() {
cin>>n>>p;
cout<<exp(n,p);
return 0;
}