Cod sursa(job #2986697)

Utilizator IandruIanis Ianachis Iandru Data 28 februarie 2023 22:35:44
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-32 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int e=1999999973;

int log(long long x,long long n)
{
    long long f=1;
    while(n)
    {
        if(n%2==1)
            f=((f%e)*x)%e;
        x=x*x;
        n=n/2;
    }
    return f%e;
}


int main()
{
    int N,P;
    fin>>N>>P;
    fout<<log(N,P);
    return 0;
}