Cod sursa(job #2635020)

Utilizator irimia_alexIrimia Alex irimia_alex Data 12 iulie 2020 23:17:38
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <stdio.h>
#define MOD 1999999973

using namespace std;

FILE* fin, * fout;

long long unsigned int pow(int x, int e) {
    if (e == 0)
        return 1;
    long long unsigned int t = pow(x, e / 2);
    t = (t * t) % MOD;
    if (e % 2 == 0) {
        return t;
    }
    else {
        return (t * x) % MOD;
    }
}

int main()
{
    fin = fopen("lgput.in", "r");
    fout = fopen("lgput.out", "w");

    int x, e;
    fscanf(fin, "%i %i", &x, &e);
    fprintf(fout,"%llu", pow(x, e));
  
    return 0;
}