Cod sursa(job #3241998)

Utilizator CondoracheAlexandruCondorache Alexandru CondoracheAlexandru Data 7 septembrie 2024 11:39:42
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define all(a) (a).begin(),(a).end()
using namespace std;
const int maxn=1e5+5;
const ll mod = 1999999973;

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

ll pw(ll n, ll exp) {
    if (exp == 0) {
        return 1;
    }
    if (exp == 1) {
        return n;
    }
    if (exp % 2 == 0) {
        return pw(n, exp / 2) * pw(n, exp / 2) % mod;
    }
    else {
        return pw(n, exp / 2 + 1) * pw(n, exp / 2) % mod;
    }
}

void solve() {
    ll n, exp;
    fin >> n >> exp;
    fout << pw(n, exp) % mod << endl;
}

int main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}