Cod sursa(job #2323601)

Utilizator alexbota2oooAlexandru Bota alexbota2ooo Data 19 ianuarie 2019 13:43:51
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
///Exponentiere in timp logaritmic
#include <fstream>
using namespace std;

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

int a, b;

long long Ridicare(int a, int b)
{
    if (b == 1)
        return a % 1999999973;
    if (b % 2 == 1)
        return a * (Ridicare(a, b / 2) % 1999999973) * (Ridicare(a, b / 2) % 1999999973);
    else
        return (Ridicare(a, b / 2) % 1999999973) * (Ridicare(a, b / 2) % 1999999973);
}

int main()
{
    fin >> a >> b;
    fout << Ridicare(a, b);
}