Cod sursa(job #2283513)

Utilizator borzaalexAlexandru Borza borzaalex Data 15 noiembrie 2018 16:27:20
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.37 kb
#include <bits/stdc++.h>
#define rest 1999999973
using namespace std;

    ifstream fin("lgput.in");
    ofstream fout("lgput.out");
long long int n,p;

int main()
{
    long long int x;

    fin>>n>>p;

    x=1;

    while(p>0)
    {
        if(p%2==1)
            x=(x*n)%rest,p--;

        n=(n*n)%rest;
        p/=2;
    }
    fout<<x;
    return 0;
}