Cod sursa(job #268046)
Utilizator | Data | 28 februarie 2009 18:01:44 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include<stdio.h>
long n,p;
long putere(int n,int p)
{
long x;
if(p==1)
return n;
if(p%2==0)
{
x=putere(n,p/2);
return (x*x)%1999999973;
}
else
return (n*putere(n,(p-1)))%1999999973;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%ld%ld",&n,&p);
printf("%ld",putere(n,p));
return 0;
}