Cod sursa(job #324835)
| Utilizator | Data | 17 iunie 2009 16:53:06 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include<stdio.h>
#define Modulo 1999999973
#define InFile "lgput.in"
#define OutFile "lgput.out"
long long n,p,y,z,number;
int main()
{
freopen(InFile,"rt",stdin);
freopen(OutFile,"wt",stdout);
scanf("%lld%lld",&n,&p);
if(p<0) { n=1/n; p*=(-1);}
y=1; z=n%Modulo;
do
{
if(p%2) y*=z;
z=(z%Modulo)*(z%Modulo);
p=p>>1;
}while(p);
printf("%lld",y);
return 0;
}
