Cod sursa(job #2376563)

Utilizator FlorinVladutCreta Florin FlorinVladut Data 8 martie 2019 16:22:57
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>

using namespace std;

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

const int MOD = 1999999973;
int n, p;

void read()
{
    fin >> n >> p;
}


int pow(int n, int p)
{
    long long rez = 1;

    while(p)
    {

        if(p % 2 == 1)
        {
            rez = (rez * n * 1LL) % MOD;
        }

        n = n * n * 1LL;


        p /= 2;
    }

    return rez;
}

void write()
{
    fout << pow(n, p);
}

int main()
{
    read();
    write();

    return 0;
}