Cod sursa(job #2499346)

Utilizator NeacsuMihaiNeacsu Mihai NeacsuMihai Data 25 noiembrie 2019 22:01:52
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>

using namespace std;

long long putere (long long x, long long e)
{
    if(e==0) return 1;
    else
    {
        if(e%2==0) return putere((x%1999999973) * (x%1999999973) %1999999973, e/2);
        else return (x%1999999973) * (putere( (x%1999999973) * (x%1999999973) %1999999973, e/2) %1999999973) %1999999973;
    }
}

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

    long long n, p;
    fin>>n>>p;

    fout<<putere(n, p);

}