Cod sursa(job #2959254)

Utilizator coso2312Cosmin Bucur coso2312 Data 30 decembrie 2022 12:58:51
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

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

int log_exp(long long a, long long b) {
    if (b == 1) {
        return a;
    }
    if (b % 2 == 0) {
        long long ok = log_exp(a, b / 2);
       //cout << ok * ok << "\n";
        return ok * ok;
    }
    return a * log_exp(a, b - 1);
}

int main() {
    long long a, b;
    fin >> a >> b;
    long long x = log_exp(a, b) % 1999999973;
    if (x < 0) {
        fout << x * -1;
    } else {
        fout << x;
    }
}