Cod sursa(job #1989963)
| Utilizator | Data | 9 iunie 2017 19:03:47 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
#define MOD 1999999973
int pow(int nV, int p) {
if (p == 0) return 1;
int aux = nV % MOD;
if (p == 1) return aux;
if (p % 2) return (aux * pow(aux * aux, p / 2)) % MOD;
return pow(aux * aux, p / 2) % MOD;
}
int main() {
std::ifstream fileIn("lgput.in");
std::ofstream fileOut("lgput.out");
int nV, p;
fileIn >> nV >> p;
fileOut << pow(nV, p);
fileIn.close();
fileOut.close();
return 0;
}
