Cod sursa(job #2508527)

Utilizator Bia11Stefanescu Bianca Mihaela Bia11 Data 12 decembrie 2019 13:35:32
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <bits/stdc++.h>
using namespace std;

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


long long n,p,y;

int main(){
    fin >> n >> p;
    if(p == 0)
    {
        fout << 1;
    }
    else{
        y = 1;
        while(p > 1)
        {
            if(p % 2 == 0)
            {
                n = n * n;
                n = n % 1999999973;
                p = p / 2;
            }
            else
            {
                y = n * y;
                n = n * n;
                n = n % 1999999973;
                y = y % 1999999973;
                p = (p - 1) / 2;
            }
        }
    }
    fout << n * y % 1999999973;

return 0;
}