Cod sursa(job #3233809)

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

int main(void) {
    FILE *in = fopen("lgput.in", "r");
    FILE *out = fopen("lgput.out", "w");

    long n, p;
    fscanf(in, "%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;
    }

    fprintf(out, "%ld\n", r);

    fclose(in);
    fclose(out);

    return 0;
}