Cod sursa(job #653840)
| Utilizator | Data | 29 decembrie 2011 00:22:17 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <stdio.h>
long long a,b,c=1999999973,i,j,rez=1;
long long divide(long long a,long long b){
if (b==1)
return a;
else{
if (b%2==0){
long long sol=divide(a,b/2);
return ((sol%c)*(sol%c))%c;
}
else{
long long sol=divide(a,b-1);
return ((sol%c)*(a%c))%c;
}
}
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld", &a, &b);
rez=divide(a,b);
printf("%lld", rez);
return 0;
}