Cod sursa(job #1394919)

Utilizator mariapascuMaria Pascu mariapascu Data 20 martie 2015 20:38:38
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <fstream>
using namespace std;

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

const int Mod = 1999999973;
int Pow(int n, int p);

int main()
{
    int n, p;
    fin >> n >> p;
    fout << Pow(n, p);

    fin.close();
    fout.close();
    return 0;
}

int Pow(int n, int p)
{
    if ( p == 0 ) return 1;
    int x = Pow(n, p / 2);
    x = (1LL * x * x) % Mod;
    if ( p % 2 == 1 ) x = (1LL * x * n) % Mod;
    return x;
}