Cod sursa(job #2428588)

Utilizator Dragos1226Dragos Chileban Dragos1226 Data 5 iunie 2019 21:02:03
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");

int ridiche(long long x,long long n)
{
    if(x<0)
    {
        x=1/x;
        n=-n;
    }
    if(n==0)
        return 1;
    long long y=1;
    while(n>1)
    {
        if(n%2==0)
        {
            x=x*x;
            n=n/2;
        }
        else
        {
            y=x*y;
            x=x*x;
            n=(n-1)/2;
        }
    }
    return x*y;
}

int main()
{
    long long n,p;
    in>>n>>p;
    out<<ridiche(n,p)%1999999973;
}