Mai intai trebuie sa te autentifici.

Cod sursa(job #3295964)

Utilizator mateicrainiceanuMatei Crainiceanu mateicrainiceanu Data 10 mai 2025 11:44:38
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <fstream>
#include <iostream>
using namespace std;

int exponentiation_by_sq(int n, int p) {
    if (n == 0)
        return 1;
    if (p % 2 == 0)
        return exponentiation_by_sq(n * n, p / 2);
    if (p % 2 == 1) {
        return n * exponentiation_by_sq(n * n, (p - 1) / 2);
    }
    return 1;
}

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

    unsigned int n, p;
    fin >> n >> p;
    fout << exponentiation_by_sq(n, p) % 1999999973;

    return 0;
}