Cod sursa(job #1513715)
Utilizator | Data | 29 octombrie 2015 21:31:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int main()
{
long long N,P,r=1;
in>>N>>P;
while(P!=1)
{
if(P%2==1)
{
r=(r*N)%1999999973;
P=P-1;
}
else
{
P=P/2;
N=(N*N)%1999999973;
}
}
out<<(r*N)%1999999973;
return 0;
}