Cod sursa(job #2190272)
| Utilizator | Data | 30 martie 2018 13:13:40 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
int fpow(int x,int n){
if(n<0)
return fpow(1/x,-n);
else if(n==0)
return 1;
else if(n==1)
return x;
else if(n%2==0)
return fpow(x*x,n/2);
else if(n%2==1)
return x*fpow(x*x,(n-1)/2);
}
int main(){
ifstream f("lgput.in");
ofstream o("lgput.out");
int n,x;
f>>x>>n;
o<<fpow(x,n)%1999999973;
return 0;
}
