Cod sursa(job #2150089)

Utilizator AndreiDumitrescuAndrei Dumitrescu AndreiDumitrescu Data 3 martie 2018 11:38:41
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <iostream>
#include <fstream>
#define m 1999999973

using namespace std;

ifstream f("lgput.in");
ofstream g("lgput.out");

int main()
{
    long long n, p, raspuns = 1;
    f >> n >> p;
    while(p)
    {
        if(p % 2 == 0)
        {
            n *= n % m;
            p = p / 2;
        }
        else
        {
            raspuns *= n % m;
            p--;
        }
    }
    g << raspuns;

}