Cod sursa(job #2779648)
Utilizator | Data | 4 octombrie 2021 16:11:37 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int m = 1999999973;
long long n,p;
int main(){
fin >> n >> p;
int a = n;
long long sol = 1;
for (int i = 0; (1<<i) <= p; ++ i)
{
if ( ((1<<i) & p) > 0)
sol= (sol * a) % m;
a=(a * a) % m;
}
fout << sol;
return 0;
}