Cod sursa(job #2690086)

Utilizator PopescuMihneaPopescu Mihnea-Valentin PopescuMihnea Data 22 decembrie 2020 22:53:25
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.33 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("lgput.in");
ofstream g ("lgput.out");
int N,P;

int exp(int N,int P)
{
    int x=1;
    if (P==1)
        return N;
    if (P%2)
        x*=N;
    return x*exp(N,P/2)*exp(N,P/2);
}

int main()
{
    f>>N>>P;
    g<<exp(N,P)%1999999973;
}