Cod sursa(job #2520175)
| Utilizator | Data | 9 ianuarie 2020 03:50:50 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <algorithm>
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long N, P;
int main()
{
long long cpy, ans = 1;
fin >> N >> P;
cpy = N;
for(int i = 0; (1 << i) <= P; i++){
if(((1 << i) & P) > 0){
ans = (ans * cpy) % MOD;
}
cpy = (cpy * cpy) % MOD;
}
fout << ans << "\n";
return 0;
}