Cod sursa(job #1601924)
Utilizator | Data | 16 februarie 2016 12:54:39 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
using namespace std;
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
int r=1,x,p;
scanf("%d %d",&x,&p);
while(p>0)
if(p%2==0)
{
x=(x*x)%1999999973;
p=p/2;
} else
{
r=(r*x)%1999999973;
p=p-1;
}
printf("%d",r%1999999973);
return 0;
}