Cod sursa(job #1537977)

Utilizator issuePop Daniel issue Data 28 noiembrie 2015 12:42:15
Problema Ridicare la putere in timp logaritmic Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long long lg_pow(long long a, long long b){
    if(b == 0) return 1;
    if(b == 1) return a % 1999999973;
    long long aux = lg_pow(a, b / 2);
    if(b % 2 == 0){
        return (1LL*aux * aux) % 1999999973;
    } else return (1LL*a * (1LL*aux * aux) % 1999999973) % 1999999973;
}

int main()
{
    long long a, b;
    fin >> a >> b;
    fout << lg_pow(a, b);
    return 0;
}