Cod sursa(job #2811175)

Utilizator CiuiGinjoveanu Dragos Ciui Data 1 decembrie 2021 13:55:40
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;
 
ifstream fin("lgput.in");
ofstream fout("lgput.out");
 
const int MOD = 1999999973;

long long power(int a, int b) {
    if (b == 0) {
        return 1 % MOD;
    }
    if (b == 1) {
        return a % MOD;
    }
    if (b % 2 == 0) {
         return (power(a, b/ 2, MOD) * power(a, b/ 2, MOD)) % MOD;
    } else {
         return (a * power(a, b - 1, MOD)) % MOD;
    }
}
 
int main() {
    long long a, b;
    fin >> a >> b;
    fout << power(a, b);
    return 0;
}