Cod sursa(job #1416596)

Utilizator MailatMailat Radu Mailat Data 8 aprilie 2015 15:17:43
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>
#define rest 1999999973
using namespace std;

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

long long pow(int x, int n)
{
    if(n == 0) return 1;
    else if(n == 1) return x;
    else if(n & 1) return pow(x*x, n/2);
    else return x * pow(x*x, (n-1)/2);
}

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

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