Cod sursa(job #715247)
Utilizator | Data | 16 martie 2012 21:52:33 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
using namespace std;
int main(void)
{
fstream fin("lgput.in",ios::in);
fstream fout("lgput.out",ios::out);
long long N,P,C,R,T;
C = 1999999973;
fin >> N >> P;
R = 1;
T = N;
while (P > 0)
{
if (P & 1)
{
R = (R * T) % C;
}
T = (T * T) % C;
P = P >> 1;
}
fout << R;
fin.close();
fout.close();
return 0;
}