Cod sursa(job #674278)
Utilizator | Data | 5 februarie 2012 22:50:04 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <stdio.h>
#define NMAX 1999999973
long long int temp;
long long int power (long long int x, long long int y)
{
if (y == 1)
return x % NMAX;
temp = power (x, y/2)%NMAX;
if (y % 2 == 0)
return (temp*temp)%NMAX;
else
return (((temp * temp)%NMAX) * (x%NMAX))%NMAX;
}
int main () {
freopen ("lgput.in", "r", stdin);
freopen ("lgput.out", "w", stdout);
long long int x, y;
scanf ("%lld %lld", &x, &y);
printf ("%lld", power(x, y)%NMAX);
return 0;
}