Cod sursa(job #1218940)
Utilizator | Data | 12 august 2014 22:48:56 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<stdio.h>
using namespace std;
long long x,p,r,n;
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d%d",&x,&n);
p=1;
r=1999999973;
while (n>0)
if (n%2==1)
{
p=(p*x)%r;
--n;
}
else
{
x=(x*x)%r;
n=n/2;
}
printf("%d",p);
return 0;
}