Cod sursa(job #1521515)
| Utilizator | Data | 10 noiembrie 2015 16:34:03 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <stdio.h>
using namespace std;
long long r,x;
int n,p;
int rptl(int p)
{
if(p==1) return n;
if(p==0) return 1;
if(p%2==0)
{
x=rptl(p/2);
r=(x*x)%1999999973;
}
else
{
x=rptl((p-1)/2);
r=(x*x)%1999999973;
r=(r*n)%1999999973;
}
return r;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d%d",&n,&p);
x=rptl(p);
printf("%d",x);
return 0;
}
