Cod sursa(job #2240446)
| Utilizator | Data | 13 septembrie 2018 13:59:38 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
const int nr = 1999999973;
int main()
{
unsigned int n, p, i;
long long ans = 1;
fin >> n >> p;
long long x = n;
for (i = 0; (1 << i) <= p; ++i)
{
if (((1 << i) & p)>0)
ans = (ans *x) % nr ;
x =(x * x) % nr;
}
fout << ans;
fout << endl;
return 0;
}
