Cod sursa(job #1244680)
Utilizator | Data | 17 octombrie 2014 23:20:51 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <stdio.h>
#define IN "lgput.in"
#define OUT "lgput.out"
typedef unsigned long Int;
static const Int mod = 1999999973;
static Int lgput(Int n, Int p)
{
Int l;
if (p == 0)
return 1;
if (p == 1)
return n;
if (p % 2)
return (n * lgput(n, p - 1)) % mod;
else
return ((l = lgput(n, p >> 1)) * l) % mod;
}
int main(void)
{
Int p, n;
freopen(IN, "r", stdin);
freopen(OUT, "w", stdout);
scanf("%llu %llu", &n, &p);
printf("%llu\n", lgput(n, p) % mod);
return 0;
}