Cod sursa(job #3289830)
Utilizator | Data | 28 martie 2025 17:27:36 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int put(int b, int e) {
int rez = 1;
while (e >= 1) {
if (e % 2 == 0) {
b = b * b % MOD;
e /= 2;
}
else {
e--;
rez = (b * rez) % MOD;
}
}
return rez;
}
int main()
{
int e, b;
fin >> b >> e;
fout << put(b, e);
return 0;
}