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