Cod sursa(job #2952380)

Utilizator coso2312Cosmin Bucur coso2312 Data 9 decembrie 2022 08:12:44
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
using namespace std;


int main() {
    long long x, n;
    int k = 1999999973;
    cin >> x >> n;
    if (n == 0) {
        cout << 1 % k;
    } else if (n % 2 == 0) {
        for (int i = 1; i <= n / 2; ++i) {
            x *= x;
        }
        cout << x % k;
    } else {
        int x_cpy = x;
        for (int i = 1; i <= n - 1; ++i) {
            x *= x;
        }
        cout << (x_cpy * x) % k;
    }
    return 0;
}