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