Cod sursa(job #2237747)
| Utilizator | Data | 2 septembrie 2018 22:37:32 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
#define Int64 long long
ifstream fin("lgput.in");
ofstream fout("lgput.in");
int powMod(Int64, Int64);
int main() {
int n, p;
fin >> n >> p;
fout << powMod(n, p);
return 0;
}
int powMod(Int64 base, Int64 exp) {
const int PRIME = 1999999973;
if (exp == 0) return 1;
if (exp & 1) {
return (base * powMod(base, --exp)) % PRIME;
}
else {
return powMod((base * base) % PRIME, exp >> 1);
}
}
