Cod sursa(job #2845639)

Utilizator stefan05Vasilache Stefan stefan05 Data 8 februarie 2022 08:05:19
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>

#define MOD 1999999973
#define ULL unsigned long long

using namespace std;

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

ULL a, b;

ULL putere(ULL, ULL);

int main()
{
    fin >>a>>b;

    fout <<putere(a, b) % MOD<<'\n';
    fout.close();
    return 0;
}

ULL putere(ULL a, ULL b)
{
    if (b == 0) return 1;
    ULL x = putere(a, b / 2) % MOD;
    return b % 2? (x * x) % MOD * a % MOD: (x*x) % MOD;
}