Cod sursa(job #957578)
Utilizator | Data | 5 iunie 2013 15:05:59 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
const int M = 1999999973;
int logpow(int x,int n){
if(n==0) return 1;
if(n%2==0){
return ((logpow(x*x,n/2))%M);
}
else{
return (x*(logpow(x*x,(n-1)/2))%M);
}
}
int a,b;
int main(){
in>>a>>b;
out<<logpow(a,b);
return 0;
}