Cod sursa(job #2989090)
Utilizator | Data | 5 martie 2023 20:57:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long Num = 1999999973;
ifstream in("lgput.in");
ofstream out("lgput.out");
int exp_by_squaring_iterative(unsigned long long x, unsigned long long n){
if (n == 0){
return 1;
}
int y = 1;
while (n > 1) {
if (n%2==0){
x =x*x;
n /=2;
}
else{
y = y*x;
x = x*x;
n =(n-1) / 2;
}
}
return x * y;
}
int main()
{
unsigned long long m,p;
in >> m >> p;
out << exp_by_squaring_iterative(m, p)%Num ;
}