Cod sursa(job #1914303)
| Utilizator | Data | 8 martie 2017 16:24:41 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
const int MOD = 1999999973;
long long pwr(long long base, long long exp) {
if (exp == 0) return 1;
if (exp % 2 == 1) return ((pwr(base, exp-1)%MOD)*(base%MOD))%MOD;
else {
long long rem = pwr(base, exp/2)%MOD;
return (rem*rem)%MOD;
}
}
int main() {
ifstream fi("lgput.in");
ofstream fo("lgput.out");
long long x, y;
fi >> x >> y;
fo << pwr(x, y);
return 0;
}
