Cod sursa(job #2704370)

Utilizator DavidAA007Apostol David DavidAA007 Data 10 februarie 2021 14:14:36
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include<iostream>
#include<fstream>
#define mod 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long int n,p,x;
int f(int n, int p)
{
    if(p==0)
        return 1;
    else
    {
        x=f(n,p/2);
        x=(x*x)%mod;
        if(p%2==1)
            x=(x*n)%mod;
        return x;
    }
}
int main()
{
    fin>>n>>p;
    x=1;
    fout<<f(n,p);
    fin.close();
    fout.close();
    return 0;
}