Cod sursa(job #2803528)
Utilizator | Data | 20 noiembrie 2021 10:26:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int const mod = 1999999973;
int main(){
int n , p;
fin >> n >> p;
int r = 1 , c = n;
for(int i = 0 ; (1 << i) <= p ; ++ i){
if (((1 << i) & p) > 0)
r = 1LL * r * c % mod;
c = 1LL * c * c % mod;
}
fout << r;
return 0;
}