Cod sursa(job #2739372)

Utilizator Mihai180315Mihai Smarandache Mihai180315 Data 7 aprilie 2021 22:51:16
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <iostream>
#include <fstream>

using namespace std;
const int MOD = 1999999973;

int lgput(long long e, int b)
{
    if (e == 1) {
        return b;
    } else if (e % 2 == 1) {
        return (1LL * b * lgput(e - 1, b)) % MOD;
    } else {
        int rez = lgput(e / 2, b);
        return (1LL * rez * rez) % MOD;
    }
}

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

    int n, p;
    fin >> n >> p;
    fout << lgput(n, p);
    fin.close();
    fout.close();
    return 0;

}