Cod sursa(job #2367676)

Utilizator AplayLazar Laurentiu Aplay Data 5 martie 2019 11:54:23
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <cstdio>

#define MOD 1999999973

long long n, p, odd, rest = 1;

int main() {
    freopen("lgput.in", "r", stdin);
    freopen("lgput.out", "w", stdout);

    scanf("%lld%lld", &n, &p);
    
    odd = n;
    while (1 < p) {
        if (1 == p % 2) {
            rest = (rest * odd) % MOD;
            --p;
        } else {
            odd = (odd * odd) % MOD;
            p /= 2;
        }
    }

    printf("%lld\n", (odd * rest) % MOD);

    return 0;
}