Cod sursa(job #889733)
| Utilizator | Data | 24 februarie 2013 17:57:27 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const long long int P=1999999973;
long long int exponentiere(int x,int n){
if(n==1)
return x%P;
else
if(n%2==1)
return ( (x%P)* (exponentiere( (x%P)*(x%P)%P,(n-1)/2)) )%P;
else
return exponentiere ( ((x%P)*(x%P)),n/2);
}
int n,p;
int main(){
f>>p>>n;
g<<exponentiere(p,n);
return 0;
}
