Cod sursa(job #1113089)

Utilizator fluture.godlikeGafton Mihnea Alexandru fluture.godlike Data 20 februarie 2014 12:23:55
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long int power(long long int a, long long int b)
{
    if(b == 0) return 1;
    if(b == 1) return a;
    int temp = power(a, b/2);
    return temp*temp*power(a, b%2);
}
int main()
{
    long long int n, p;
    fin>>n>>p;
    long long int res = power(n, p);
    fout<<res%1999999973<<endl;
    return 0;
}