Cod sursa(job #2569586)

Utilizator unchnounMihai Panduru unchnoun Data 4 martie 2020 12:43:51
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda r3capitusulare Marime 0.46 kb
#include <fstream>
#include <cmath>
using namespace std;

const int mod = 1999999973;
long long n, p;

long long putere(long long a, long long b)
{
    if (!b)
        return 1;
    else if (b % 2)
        return (a * putere(a * a % mod, b / 2) % mod) % mod;
    else
        return (putere(a * a % mod, b / 2) % mod);
}

int main()
{
    ifstream fin("lgput.in");
    ofstream fout("lgput.out");
    fin >> n >> p;
    fout << putere(n, p);
}