Cod sursa(job #2998371)
| Utilizator | Data | 9 martie 2023 12:41:41 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int fast_pow(int base, int exponent, int mod) {
long long aux = 1;
while (exponent > 1) {
if (exponent % 2 == 1)
aux = 1ll * aux * base % mod;
base = 1ll * base * base % mod;
exponent /= 2;
}
return 1ll * base * aux % mod;
}
#define MOD 1999999973
int main() {
int n, p;
f >> n >> p;
g << fast_pow(n, p , MOD);
return 0;
}