Cod sursa(job #2501434)

Utilizator ralucaantonAnton Raluca ralucaanton Data 29 noiembrie 2019 18:47:01
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int const m = 1999999973;
long long b, e;

long long putere(long long b, long long e)
{
    if(e==0)
        return 1;
    else
    {
        if(e%2==0)
            return ( ( putere(b,e/2) % m ) * ( putere(b,e/2) % m ) ) % m;
        else
            return ( ( b % m ) * ( putere(b,e-1) % m ) ) % m;
    }
}

int main()
{
    fin>>b>>e;     // b=baza, e=exponent
    fout<<putere(b,e)%m;
    fin.close();
    fout.close();
    return 0;
}