Cod sursa(job #504164)
| Utilizator | Data | 26 noiembrie 2010 21:07:58 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <stdio.h>
#define NUMBER 1999999973
long long int pow_log(unsigned int n, unsigned int p)
{
long long int res=1, tmp=n;
while ( p != 0)
{
if ( p%2 == 0)
{
p /= 2;
tmp *= tmp;
}
else
{
--p;
res *= tmp;
}
}
return res;
}
int main(void)
{
unsigned int n, p;
long long int pow;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%u %u",&n, &p);
pow = pow_log(n,p);
printf("%lld\n",pow % NUMBER);
return 0;
}
