Cod sursa(job #2033272)

Utilizator tudormaximTudor Maxim tudormaxim Data 6 octombrie 2017 15:51:42
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.56 kb
#include <stdio.h>
#include <stdlib.h>
typedef long long LL;

const LL mod = 1999999973;

LL log_pow(LL n, LL p) {
    LL ans = 1;
    while (p > 0) {
        if (p & 1) ans = (1LL * ans * n) % mod;
        n = (1LL * n * n) % mod;
        p = p >> 1;
    }
    return ans;
}

int main(void) {
    FILE *fin = fopen("lgput.in", "r");
    FILE *fout = fopen("lgput.out", "w");
    LL n, p, ans;
    fscanf(fin, "%lld %lld", &n, &p);
    ans = log_pow(n, p);
    fprintf(fout, "%lld\n", ans);
    fclose(fin);
    fclose(fout);
    return 0;
}