Cod sursa(job #1901217)
Utilizator | Data | 3 martie 2017 20:06:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const int n_max = 10001;
const int m = 1999999973;
unsigned int i, n, p;
long long a, sol = 1;
int main()
{
f>>n>>p;
a = n;
for (i = 0; (1<<i) <= p; ++ i)
{
if ( ((1<<i) & p) > 0)
sol= (sol * a) % m;
a=(a * a) % m;
}
g<<sol;
return 0;
}