Cod sursa(job #2982892)
Utilizator | Bicu Codrut Eduard Edyci123 | Data | 21 februarie 2023 02:08:15 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
#define ll long long
#define MOD 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n, p;
ll getLogPow(ll n, ll p) {
if (p == 0) {
return 1;
}
if (p % 2 == 0) {
return (getLogPow(n * n % MOD, p / 2));
} else {
return n * getLogPow(n, p - 1) % MOD;
}
}
int main() {
f >> n >> p;
g << getLogPow(n, p);
return 0;
}