Cod sursa(job #1131162)

Utilizator Corina1997Todoran Ana-Corina Corina1997 Data 28 februarie 2014 18:12:55
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>
#define MOD 1999999973
using namespace std;

ifstream is("lgput.in");
ofstream os("lgput.out");

int x, n;
long long int Pow( int n, int x );

int main()
{
    is >> n >> x;

    os << Pow( n, x );

    is.close();
    os.close();
    return 0;
}

long long int Pow( int n, int x )
{
    if ( x == 0 ) return 1;
    if ( x == 1 ) return n;
    long long aux = Pow( n, x / 2 );
    aux = ( aux * aux ) % MOD;
    if ( x % 2 == 1 )
        aux *= n;
    return aux;
}