Cod sursa(job #1396317)
| Utilizator | Data | 22 martie 2015 13:47:15 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
#include <iostream>
std::ifstream fin("lgput.in");
std::ofstream fout("lgput.out");
int put(int x, int n) {
if (n == 0) {return 1;}
if (n == 1) {return x;}
if (n % 2 == 0) {
return put((x * x), n / 2)%1999999973;
} else
return put((x * x), n / 2 - 1)%1999999973;
}
int main() {
int a, b;
fin >> a >> b;
fout << put(a, b);
return 0;
}