Cod sursa(job #2971551)

Utilizator Mihai_OctMihai Octavian Mihai_Oct Data 27 ianuarie 2023 16:24:46
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>
#define mod 1999999973

using namespace std;

ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long a, b;

long long put(long long a, long long b) {
    long long p = 1;
    while(b) {
        if((b & 1) == 1) p = (p * a) % mod;
        a = ((a % mod) * (a % mod)) % mod;
        b >>= 1;
    }
    return p;
}

int main() {
    ios_base::sync_with_stdio(false);
    fin.tie(NULL);
    fin >> a >> b;
    fout << put(a, b);

    return 0;
}