Cod sursa(job #1509186)
Utilizator | Data | 23 octombrie 2015 16:24:27 | |
---|---|---|---|
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;
ifstream in ("lgput.in");
ofstream out ("lgput.out");
int main()
{
unsigned long long N,R=1,P,nr;
in>>N>>P;
while(P!=1)
{
if(P%2==0)
{
P=P/2;
N=N*N%1999999973;
}
else
{
P=P-1;
R=R*N%1999999973;
}
}
nr=N*R;
out<<nr%1999999973<<'\n';
return 0;
}