Cod sursa(job #1878958)
Utilizator | Data | 14 februarie 2017 17:12:27 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
#define md 1999999973
using namespace std;
ifstream fi ("lgput.in");
ofstream fo ("lgput.out");
long long n, p, s = 1, a = 1;
int main ()
{
fi >> n >> p;
while(p!=0)
{
while (2*a <= p)
{
a*=2;
n = n*n%md;
}
s = s*n%md;
p-=a;
a = 1;
}
fo << s;
return 0;
}