Cod sursa(job #2540016)

Utilizator BluThund3rRadu George BluThund3r Data 6 februarie 2020 17:29:38
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>
#define MOD 1999999973
using namespace std;

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

int n, exp;

long long quick_power(int base, int exponent)
{
    long long result = 1;

   while(exponent)
   {
       if(exponent % 2 != 0)
            result = (1LL * result * base) % MOD;

        base = (1LL * base * base) % MOD;
        exponent /= 2;
   }

   return result;
}

int main()
{
    in >> n >> exp;

    out << quick_power(n, exp);

    return 0;
}