Cod sursa(job #2257258)

Utilizator AxellbenCretu Alexandru Axellben Data 9 octombrie 2018 21:10:24
Problema Ridicare la putere in timp logaritmic Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>
#include <iostream>

using namespace std;

ifstream fin("lgput.in");
ofstream fout("lgput.out");

const int MOD = 1999999973;

long long power(int x, int y) {
  if (y == 0) {
    return 1;
  }
  int r = power(x, y / 2);
  if (y % 2 == 0) {
    return (1LL * r * r) % MOD;
  } else {
    return (1LL * x * r * r) % MOD;
  }
}

int main() {
  int N, P;
  fin >> N >> P;
  fout << power(N, P);
}