Cod sursa(job #3233807)

Utilizator tmaxmaxTeodor Maxim tmaxmax Data 4 iunie 2024 23:37:59
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.31 kb
#include <stdio.h>

int main(void) {
    long n, p;
    scanf("%ld %ld", &n, &p);

    const long mod = 1999999973L;

    long r = 1, s = n;
    while (p > 0) {
        if (p % 2 == 1) {
            r = (r * s) % mod;
        }
        s = (s * s) % mod;
        p /= 2;
    }

    printf("%ld\n", r);

    return 0;
}