Cod sursa(job #3238656)

Utilizator raulthestormIlie Raul Ionut raulthestorm Data 28 iulie 2024 15:41:56
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;

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

const int MOD = 1999999973;

long long pwr(unsigned int a, unsigned int b)
{
    int p = 1;
    while(b)
    {
        if(b % 2)
            p = 1LL * p * a % MOD;
        a = 1LL * a * a % MOD;
        b /= 2;
    }
    return p;
}

int main()
{
    unsigned int n, p;
    long long sol;
    f >> n >> p;
    n %= MOD;
    sol = pwr(n, p);
    g << sol;
    f.close();
    g.close();
    return 0;
}