Cod sursa(job #2150568)

Utilizator andreigasparoviciAndrei Gasparovici andreigasparovici Data 3 martie 2018 17:22:12
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
// Ridicare la putere in timp logaritmic
#include <cstdio>
using namespace std;

typedef long long LL;

const int MOD = 66013;

LL logPow(LL x, LL p) {
    LL ans;
    for (ans = 1; p;  p = (p & 1) ? p - 1 : p >> 1) {
        if (p & 1) ans = (ans * x) % MOD;
        else x = (x * x) % MOD;  
    }
    return ans;
}

int main()
{
    freopen("lgput.in", "r", stdin);
    freopen("lgput.out", "w", stdout);
    LL a, b;
    scanf("%lld %lld ", &a, &b);
    printf("%lld\n", logPow(a % MOD, b));
    return 0;
}