Cod sursa(job #1518247)
| Utilizator | Data | 5 noiembrie 2015 19:32:55 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| 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 1;
if(P == 1) return N;
if(P % 2 == 0) return (LgPut(N*N%DIVISOR, P/2))%DIVISOR;
else return (N * LgPut(N*N%DIVISOR, (P-1)/2))%DIVISOR;
}
int main(){
long long N,P;
in >> N >> P;
out << LgPut(N,P) << "\n";
return 0;
}