Cod sursa(job #2163834)
| Utilizator | Data | 12 martie 2018 20:07:38 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <stdio.h>
typedef unsigned long long ull;
static const ull mod = 1999999973;
static ull lgput(ull n, ull p)
{
ull l;
if (p == 0) {
return 1;
}
if (p == 1) {
return n;
}
l = lgput(n, p >> 1);
if (p % 2) {
return l * l % mod * n % mod;
}
return l * l % mod;
}
int main(void)
{
ull p, n;
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%llu %llu", &n, &p);
printf("%llu", lgput(n, p));
return 0;
}
