Cod sursa(job #583641)
| Utilizator | Data | 21 aprilie 2011 16:04:30 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
#include <cmath>
#include <iostream>
using namespace std;
long rp(const unsigned long& x, unsigned const long& n) {
if(n == 0) return 1;
if(n % 2 == 0) return (unsigned long)(pow(rp(x, n/2) % 1999999973, 2)) % 1999999973;
return x * rp(x, n-1) % 1999999973;
}
int main(void) {
long n, p;
// citire
ifstream fin("lgput.in");
fin >> n >> p;
fin.close();
// afisare
ofstream fout("lgput.out");
fout << rp(n, p);
fout.close();
return 0;
}
