Cod sursa(job #3276990)

Utilizator andrei_botorogeanuBotorogeanu Andrei andrei_botorogeanu Data 15 februarie 2025 11:05:23
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>
#define MOD 1999999973
#define FIN "lgput.in"
#define FOUT "lgput.out"
#define LL long long

using namespace std;

LL pow(LL base, LL exp) {

    LL ans = 1;

    while( exp != 0 ) {

        if(exp % 2 != 0) {

            ans = (ans * base ) % MOD;
        }

        base = (base * base ) % MOD;

        exp /= 2;
    }

    return ans % MOD;
}

int main(int argc, char const *argv[]) {

  LL a, b;
  ifstream fin(FIN);
  ofstream fout(FOUT);
  fin>>a>>b;
  fout<<pow(a,b);
  return 0;
}