Cod sursa(job #2922690)

Utilizator TheRomulusIvan Remus TheRomulus Data 9 septembrie 2022 17:51:19
Problema Ridicare la putere in timp logaritmic Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <queue>
#include <stack>

#define M 1999999973

using namespace std;

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

typedef long long ll;

ll computePower(ll base, ll exponent) {
    if (exponent <= 0) {
        return 1;
    }
    ll x = computePower(base, exponent / 2) % M;
    return ((exponent % 2) ? base : 1) * x * x % M;
}

void Solve() {
    ll n, m, p;
    fin >> n >> m;
    p = computePower(n, m);
    fout << p << '\n';
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    Solve();
    return 0;
}