Cod sursa(job #3132351)
| Utilizator | Data | 22 mai 2023 13:31:37 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <fstream>
using namespace std;
int exp(int a, int b) {
if (b == 0)return 1;
else
if (b == 1)return a;
if (b % 2 == 0)return exp(a, b / 2)*exp(a, b / 2)%1999999973;
else return a*exp(a, b / 2)*exp(a, b / 2) % 1999999973;
}
int main() {
int n, p;
ifstream fi("lgput.in");
fi >> n >> p;
fi.close();
ofstream fo("lgput.out");
fo << exp(n, p);
fo.close();
}