Cod sursa(job #3221047)
| Utilizator | Data | 5 aprilie 2024 19:22:28 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int MOD = 1999999973;
int N, P, aux, v[11], k, R = 1;
int main () {
fin >> N >> P;
while(P) {
v[++k] = P % 2;
P /= 2;
}
for(int i = k; i >= 1; i--) {
aux = R;
if(v[i] == 1)
R = (1LL * R * N) % MOD;
R = (1LL * R * aux) % MOD;
}
fout << R << '\n';
fin.close ();
fout.close ();
return 0;
}