Cod sursa(job #1318970)
Utilizator | Data | 16 ianuarie 2015 15:29:36 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
long long N,P,M,x,y;
fin>>N>>P;
M=1999999973;
y=1;
x=N%M;
while(P!=0)
{
if(P%2==1)
{
y=(y*x)%M;
}
x=(x*x)%M;
P=P/2;
}
fout<<y;
return 0;
}