Cod sursa(job #1439603)
Utilizator | Data | 22 mai 2015 19:56:35 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
int x, p, n;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long lgput(int n, int p){
if(p == 0){
return 1;
}else{
long long aux = lgput(n,p/2);
if(p%2 == 0){
return(aux*aux)%1999999973;
}else{
return (aux*aux)%1999999973 * n%1999999973;
}
}
}
int main(){
fin>>n>>p;
x = lgput(n,p);
fout<<x;
}