Cod sursa(job #3136079)

Utilizator yungxristfaur cristian yungxrist Data 5 iunie 2023 13:25:22
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
long long int recPow(unsigned int n, unsigned int p)
{
    if (p < 0)
        return recPow(1 / n, -p);
    if (p == 0)
        return 1;
    if (p % 2 == 0)
    {
        return recPow(n * n, p / 2);
        cout << 'a';
    }
    if (p % 2 == 1)
        return n * recPow(n * n, p / 2);
}
int main()
{
    long long int n;
    long long int p;
    int pow;
    //int x=1999999973;
    in >> n >> p;
    pow = recPow(n, p);
    out << pow % 1999999973;
    return 0;
}