Cod sursa(job #1416606)

Utilizator MailatMailat Radu Mailat Data 8 aprilie 2015 15:24:57
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <fstream>
#define rest 1999999973
typedef long long ll;
using namespace std;

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

ll pow(ll x, ll n)
{
    if(n == 0) return 1;
    else if(n == 1) return x;
    else if(n%2 != 0) return x * pow(x*x, (n-1)/2);
    else return pow(x*x, n/2);
}

int main()
{
    ll x, n;
    ll rez;

    fin >> x >> n;
    rez = pow(x,n);
    fout << rez%rest;
    return 0;
}