Cod sursa(job #2639711)

Utilizator Edyci123Bicu Codrut Eduard Edyci123 Data 3 august 2020 16:22:58
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.34 kb
#include <fstream>
#define MOD 1999999973

using namespace std;

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

long long n,p;

int main()
{

    f>>n>>p;
    long long sol=n;
    while(p>1)
    {
        if(p%2==0)
            sol*=sol,p/=2;
        else
            sol*=n,p--;
    }

    g<<sol;

    return 0;

}