Cod sursa(job #2367628)

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

#define MOD 1999999973

long long n, p, ans;

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

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

    printf("%lld\n", ans);

    return 0;
}