Cod sursa(job #3264961)
| Utilizator | Data | 26 decembrie 2024 00:17:08 | |
|---|---|---|---|
| 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>
using namespace std;
const int MOD = 1999999973;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int lgput(int n, int a){
int ans = 1, pwr = n;
for(int i = 0; i < 32; i++){
int bt = (a>>i)&1;
ans = (bt ? (1ll*ans*pwr)%MOD : ans);
pwr = (1ll*pwr*pwr)%MOD;
}
return ans;
}
int main() {
int n,p;
fin >> n >> p;
fout << lgput(n, p);
return 0;
}
