Cod sursa(job #1517943)
| Utilizator | Data | 5 noiembrie 2015 00:41:53 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <stdio.h>
#include <fstream>
#define DIVISOR 1999999973
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
long long LgPut(long long N, long long P){
if (P < 0) return LgPut(1/N, -P);
if(P == 1) return N;
if(P % 2 == 0) return LgPut(N*N, P/2);
if(P % 2 == 1) return N*LgPut(N*N, (P-1)/2);
}
int main(){
long long N, P;
in >> N >> P;
out << LgPut(N, P)%DIVISOR << "\n";
return 0;
}