Cod sursa(job #1761679)

Utilizator infomaxInfomax infomax Data 22 septembrie 2016 18:08:00
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>

using namespace std;

ifstream F ("lgput.in");
ofstream G ("lgput.out");

unsigned int power(int x, int P)
{
    if (!P) return 1;
    else if (P == 1) return x;
    else if (P % 2 == 0) return power(x * x, P / 2);
    else if (P % 2) return x * power(x * x, (P - 1) / 2);
}

unsigned int n, p;
int main()
{
    F >> n >> p;
    G << power(n, p) % 1999999973;
    return 0;
}