Cod sursa(job #2982552)
Utilizator | Data | 20 februarie 2023 14:12:48 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <bits/stdc++.h>
///#define nrMagic 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int nrMagic = 1999999973;
long long n, p, rez = 1;
int main()
{
f >> n >> p;
while(p) {
if (p & 1) {
rez = (rez * n) % nrMagic;
p--;
}
n = (n * n) % nrMagic;
p /= 2;
}
g << rez;
return 0;
}