Cod sursa(job #177323)
| Utilizator | Data | 12 aprilie 2008 17:50:52 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <stdio.h>
#define M 1999999973
#define impar(x) ((x & 1) == 1)
#define t long long
t exp_log(t b, t e)
{
if(e==0 || e==1) return b % M;
if(impar(e))
{
t rp = exp_log(b, e-1);
return (rp*(b%M))%M;
}
else
{
t rp = exp_log(b, e/2);
return (rp*rp)%M;
}
}
int main()
{
t baza, exponent;
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%lld %lld",&baza,&exponent);
fclose(stdin);
printf("%lld\n",exp_log(baza,exponent));
fclose(stdout);
}
